module cubed_sphere_domain_array_mod

  use var_types_mod
  use cubed_sphere_objects
  use cubed_sphere_domain_mod
  use cubed_sphere_halo_mod

  implicit none

  type cubed_sphere_domain_array_type
    logical :: initialized = .false.
    logical :: active      = .false.
    type(cubed_sphere_domain_type), pointer :: domain => null()
    type(cubed_sphere_halo_type) halo(8)
    ! Arrays for storing user data
    ! Dimension columns:
    ! 1. quadtrature or ghost point
    ! 2. x-axis
    ! 3. y-axis
    ! 4. vertical level
    ! 5. variable
    ! Subscript:
    ! c. cell
    ! l. left cell edge quadtrature
    ! r. right cell edge quadtrature
    ! t. top cell edge quadtrature
    ! b. bottom cell edge quadtrature
    ! q. cell quadtrature
    ! g. ghost point
    ! h. with halo elements
    !                                1 2 3 4 5
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_c_h_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_ca_h_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_cq_h_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_c_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_ca_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_cq_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_l_h_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_lq_h_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_l_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_lq_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_r_h_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_rq_h_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_r_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_rq_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_t_h_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_tq_h_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_t_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_tq_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_b_h_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_bq_h_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_b_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_bq_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_u_h_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_uq_h_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_u_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_uq_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_d_h_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_dq_h_r8
    real(r8), allocatable, dimension(  :,:,  :) :: a_2d_d_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_dq_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_g_h_r8
    real(r8), allocatable, dimension(:,:,:,  :) :: a_2d_g_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_c_h_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_ca_h_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_cq_h_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_c_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_ca_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_cq_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_l_h_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_lq_h_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_l_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_lq_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_r_h_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_rq_h_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_r_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_rq_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_t_h_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_tq_h_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_t_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_tq_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_b_h_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_bq_h_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_b_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_bq_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_u_h_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_uq_h_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_u_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_uq_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_d_h_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_dq_h_r8
    real(r8), allocatable, dimension(  :,:,:,:) :: a_3d_d_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_dq_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_g_h_r8
    real(r8), allocatable, dimension(:,:,:,:,:) :: a_3d_g_r8
    logical , allocatable, dimension(  :,:,  :) :: a_2d_c_l
    logical , allocatable, dimension(  :,:,:,:) :: a_3d_c_l
    logical , allocatable, dimension(  :,:,  :) :: a_2d_c_h_l
    logical , allocatable, dimension(  :,:,:,:) :: a_3d_c_h_l
    integer , allocatable, dimension(  :,:,  :) :: a_2d_c_h_i4
    integer , allocatable, dimension(  :,:,:,:) :: a_3d_c_h_i4
    integer , allocatable, dimension(  :,:,  :) :: a_2d_c_i4
    integer , allocatable, dimension(  :,:,:,:) :: a_3d_c_i4
    integer , allocatable, dimension(  :,:,  :) :: a_2d_ca_h_i4
    integer , allocatable, dimension(  :,:,:,:) :: a_3d_ca_h_i4
    integer , allocatable, dimension(  :,:,  :) :: a_2d_ca_i4
    integer , allocatable, dimension(  :,:,:,:) :: a_3d_ca_i4
  contains
    procedure :: init            => cubed_sphere_domain_array_init
    procedure :: clear           => cubed_sphere_domain_array_clear
    procedure :: allocate_arrays => cubed_sphere_domain_array_allocate_arrays
    generic   :: get_array       => cubed_sphere_domain_array_get_array_2d_r8  , &
                                    cubed_sphere_domain_array_get_array_3d_r8_1, &
                                    cubed_sphere_domain_array_get_array_3d_r8_2, &
                                    cubed_sphere_domain_array_get_array_4d_r8_1, &
                                    cubed_sphere_domain_array_get_array_4d_r8_2, &
                                    cubed_sphere_domain_array_get_array_5d_r8  , &
                                    cubed_sphere_domain_array_get_array_2d_l_1 , &
                                    cubed_sphere_domain_array_get_array_3d_l_1 , &
                                    cubed_sphere_domain_array_get_array_2d_i4_1, &
                                    cubed_sphere_domain_array_get_array_2d_i4_2, &
                                    cubed_sphere_domain_array_get_array_3d_i4_1, &
                                    cubed_sphere_domain_array_get_array_3d_i4_2
    procedure, private :: cubed_sphere_domain_array_get_array_2d_r8
    procedure, private :: cubed_sphere_domain_array_get_array_3d_r8_1
    procedure, private :: cubed_sphere_domain_array_get_array_3d_r8_2
    procedure, private :: cubed_sphere_domain_array_get_array_4d_r8_1
    procedure, private :: cubed_sphere_domain_array_get_array_4d_r8_2
    procedure, private :: cubed_sphere_domain_array_get_array_5d_r8
    procedure, private :: cubed_sphere_domain_array_get_array_2d_l_1
    procedure, private :: cubed_sphere_domain_array_get_array_3d_l_1
    procedure, private :: cubed_sphere_domain_array_get_array_2d_i4_1
    procedure, private :: cubed_sphere_domain_array_get_array_2d_i4_2
    procedure, private :: cubed_sphere_domain_array_get_array_3d_i4_1
    procedure, private :: cubed_sphere_domain_array_get_array_3d_i4_2
    final :: cubed_sphere_domain_array_final
  end type cubed_sphere_domain_array_type

contains

  subroutine cubed_sphere_domain_array_init(this, domain)

    class(cubed_sphere_domain_array_type), intent(inout), target :: this
    type(cubed_sphere_domain_type)       , intent(in   ), target :: domain

    integer orient

    this%domain => domain
    this%initialized = .true.
    this%active = domain%active

    ! Initialize halo objects.
    if (domain%active) then
      ! Halos of initialized but not active domains are handled by active domains.
      do orient = 1, size(proc%ngb)
        call this%halo(orient)%init(domain, orient, host_id=proc%id, proc_id=proc%ngb(orient)%id)
      end do
    end if

  end subroutine cubed_sphere_domain_array_init

  subroutine cubed_sphere_domain_array_clear(this)

    class(cubed_sphere_domain_array_type), intent(inout) :: this

    if (allocated(this%a_2d_c_h_r8 )) deallocate(this%a_2d_c_h_r8 )
    if (allocated(this%a_2d_c_r8   )) deallocate(this%a_2d_c_r8   )
    if (allocated(this%a_2d_ca_h_r8)) deallocate(this%a_2d_ca_h_r8)
    if (allocated(this%a_2d_ca_r8  )) deallocate(this%a_2d_ca_r8  )
    if (allocated(this%a_2d_cq_h_r8)) deallocate(this%a_2d_cq_h_r8)
    if (allocated(this%a_2d_cq_r8  )) deallocate(this%a_2d_cq_r8  )
    if (allocated(this%a_3d_c_h_r8 )) deallocate(this%a_3d_c_h_r8 )
    if (allocated(this%a_3d_c_r8   )) deallocate(this%a_3d_c_r8   )
    if (allocated(this%a_3d_ca_h_r8)) deallocate(this%a_3d_ca_h_r8)
    if (allocated(this%a_3d_ca_r8  )) deallocate(this%a_3d_ca_r8  )
    if (allocated(this%a_3d_cq_h_r8)) deallocate(this%a_3d_cq_h_r8)
    if (allocated(this%a_3d_cq_r8  )) deallocate(this%a_3d_cq_r8  )
    if (allocated(this%a_2d_l_h_r8 )) deallocate(this%a_2d_l_h_r8 )
    if (allocated(this%a_2d_l_r8   )) deallocate(this%a_2d_l_r8   )
    if (allocated(this%a_2d_lq_h_r8)) deallocate(this%a_2d_lq_h_r8)
    if (allocated(this%a_2d_lq_r8  )) deallocate(this%a_2d_lq_r8  )
    if (allocated(this%a_2d_g_h_r8 )) deallocate(this%a_2d_g_h_r8 )
    if (allocated(this%a_2d_g_r8   )) deallocate(this%a_2d_g_r8   )
    if (allocated(this%a_3d_l_h_r8 )) deallocate(this%a_3d_l_h_r8 )
    if (allocated(this%a_3d_l_r8   )) deallocate(this%a_3d_l_r8   )
    if (allocated(this%a_3d_lq_h_r8)) deallocate(this%a_3d_lq_h_r8)
    if (allocated(this%a_3d_lq_r8  )) deallocate(this%a_3d_lq_r8  )
    if (allocated(this%a_2d_r_h_r8 )) deallocate(this%a_2d_r_h_r8 )
    if (allocated(this%a_2d_r_r8   )) deallocate(this%a_2d_r_r8   )
    if (allocated(this%a_2d_rq_h_r8)) deallocate(this%a_2d_rq_h_r8)
    if (allocated(this%a_2d_rq_r8  )) deallocate(this%a_2d_rq_r8  )
    if (allocated(this%a_3d_r_h_r8 )) deallocate(this%a_3d_r_h_r8 )
    if (allocated(this%a_3d_r_r8   )) deallocate(this%a_3d_r_r8   )
    if (allocated(this%a_3d_rq_h_r8)) deallocate(this%a_3d_rq_h_r8)
    if (allocated(this%a_3d_rq_r8  )) deallocate(this%a_3d_rq_r8  )
    if (allocated(this%a_2d_t_h_r8 )) deallocate(this%a_2d_t_h_r8 )
    if (allocated(this%a_2d_t_r8   )) deallocate(this%a_2d_t_r8   )
    if (allocated(this%a_2d_tq_h_r8)) deallocate(this%a_2d_tq_h_r8)
    if (allocated(this%a_2d_tq_r8  )) deallocate(this%a_2d_tq_r8  )
    if (allocated(this%a_3d_t_h_r8 )) deallocate(this%a_3d_t_h_r8 )
    if (allocated(this%a_3d_t_r8   )) deallocate(this%a_3d_t_r8   )
    if (allocated(this%a_3d_tq_h_r8)) deallocate(this%a_3d_tq_h_r8)
    if (allocated(this%a_3d_tq_r8  )) deallocate(this%a_3d_tq_r8  )
    if (allocated(this%a_2d_b_h_r8 )) deallocate(this%a_2d_b_h_r8 )
    if (allocated(this%a_2d_b_r8   )) deallocate(this%a_2d_b_r8   )
    if (allocated(this%a_2d_bq_h_r8)) deallocate(this%a_2d_bq_h_r8)
    if (allocated(this%a_2d_bq_r8  )) deallocate(this%a_2d_bq_r8  )
    if (allocated(this%a_2d_u_h_r8 )) deallocate(this%a_2d_u_h_r8 )
    if (allocated(this%a_2d_u_r8   )) deallocate(this%a_2d_u_r8   )
    if (allocated(this%a_2d_uq_h_r8)) deallocate(this%a_2d_uq_h_r8)
    if (allocated(this%a_2d_uq_r8  )) deallocate(this%a_2d_uq_r8  )
    if (allocated(this%a_2d_d_h_r8 )) deallocate(this%a_2d_d_h_r8 )
    if (allocated(this%a_2d_d_r8   )) deallocate(this%a_2d_d_r8   )
    if (allocated(this%a_2d_dq_h_r8)) deallocate(this%a_2d_dq_h_r8)
    if (allocated(this%a_2d_dq_r8  )) deallocate(this%a_2d_dq_r8  )
    if (allocated(this%a_3d_b_h_r8 )) deallocate(this%a_3d_b_h_r8 )
    if (allocated(this%a_3d_b_r8   )) deallocate(this%a_3d_b_r8   )
    if (allocated(this%a_3d_bq_h_r8)) deallocate(this%a_3d_bq_h_r8)
    if (allocated(this%a_3d_bq_r8  )) deallocate(this%a_3d_bq_r8  )
    if (allocated(this%a_3d_u_h_r8 )) deallocate(this%a_3d_u_h_r8 )
    if (allocated(this%a_3d_u_r8   )) deallocate(this%a_3d_u_r8   )
    if (allocated(this%a_3d_uq_h_r8)) deallocate(this%a_3d_uq_h_r8)
    if (allocated(this%a_3d_uq_r8  )) deallocate(this%a_3d_uq_r8  )
    if (allocated(this%a_3d_d_h_r8 )) deallocate(this%a_3d_d_h_r8 )
    if (allocated(this%a_3d_d_r8   )) deallocate(this%a_3d_d_r8   )
    if (allocated(this%a_3d_dq_h_r8)) deallocate(this%a_3d_dq_h_r8)
    if (allocated(this%a_3d_dq_r8  )) deallocate(this%a_3d_dq_r8  )
    if (allocated(this%a_3d_g_h_r8 )) deallocate(this%a_3d_g_h_r8 )
    if (allocated(this%a_3d_g_r8   )) deallocate(this%a_3d_g_r8   )

    this%initialized = .false.

  end subroutine cubed_sphere_domain_array_clear

  subroutine cubed_sphere_domain_array_allocate_arrays(this, var_stack, update_var_stack)

    class(cubed_sphere_domain_array_type), intent(inout) :: this
    type(var_stack_type), intent(inout) :: var_stack
    logical, intent(in) :: update_var_stack

    integer i, pes, pee
    integer n_2d_c_h_r8, n_2d_c_r8, n_3d_c_h_r8, n_3d_c_r8, n_2d_cq_h_r8, n_2d_cq_r8, n_3d_cq_h_r8, n_3d_cq_r8
    integer n_2d_l_h_r8, n_2d_l_r8, n_3d_l_h_r8, n_3d_l_r8, n_2d_lq_h_r8, n_2d_lq_r8, n_3d_lq_h_r8, n_3d_lq_r8
    integer n_2d_r_h_r8, n_2d_r_r8, n_3d_r_h_r8, n_3d_r_r8, n_2d_rq_h_r8, n_2d_rq_r8, n_3d_rq_h_r8, n_3d_rq_r8
    integer n_2d_t_h_r8, n_2d_t_r8, n_3d_t_h_r8, n_3d_t_r8, n_2d_tq_h_r8, n_2d_tq_r8, n_3d_tq_h_r8, n_3d_tq_r8
    integer n_2d_b_h_r8, n_2d_b_r8, n_3d_b_h_r8, n_3d_b_r8, n_2d_bq_h_r8, n_2d_bq_r8, n_3d_bq_h_r8, n_3d_bq_r8
    integer n_2d_d_h_r8, n_2d_d_r8, n_3d_d_h_r8, n_3d_d_r8, n_2d_dq_h_r8, n_2d_dq_r8, n_3d_dq_h_r8, n_3d_dq_r8
    integer n_2d_u_h_r8, n_2d_u_r8, n_3d_u_h_r8, n_3d_u_r8, n_2d_uq_h_r8, n_2d_uq_r8, n_3d_uq_h_r8, n_3d_uq_r8
    integer n_2d_g_h_r8, n_2d_g_r8, n_3d_g_h_r8, n_3d_g_r8
    integer                                                 n_2d_ca_h_r8, n_2d_ca_r8, n_3d_ca_h_r8, n_3d_ca_r8
    integer n_2d_c_h_l, n_2d_c_l, n_2d_c_h_i4, n_2d_c_i4, n_2d_ca_h_i4, n_2d_ca_i4
    integer n_3d_c_h_l, n_3d_c_l, n_3d_c_h_i4, n_3d_c_i4, n_3d_ca_h_i4, n_3d_ca_i4

    n_2d_c_h_r8 = 0; n_2d_c_r8 = 0; n_3d_c_h_r8 = 0; n_3d_c_r8 = 0; n_2d_cq_h_r8 = 0; n_2d_cq_r8 = 0; n_3d_cq_h_r8 = 0; n_3d_cq_r8 = 0
    n_2d_l_h_r8 = 0; n_2d_l_r8 = 0; n_3d_l_h_r8 = 0; n_3d_l_r8 = 0; n_2d_lq_h_r8 = 0; n_2d_lq_r8 = 0; n_3d_lq_h_r8 = 0; n_3d_lq_r8 = 0
    n_2d_r_h_r8 = 0; n_2d_r_r8 = 0; n_3d_r_h_r8 = 0; n_3d_r_r8 = 0; n_2d_rq_h_r8 = 0; n_2d_rq_r8 = 0; n_3d_rq_h_r8 = 0; n_3d_rq_r8 = 0
    n_2d_t_h_r8 = 0; n_2d_t_r8 = 0; n_3d_t_h_r8 = 0; n_3d_t_r8 = 0; n_2d_tq_h_r8 = 0; n_2d_tq_r8 = 0; n_3d_tq_h_r8 = 0; n_3d_tq_r8 = 0
    n_2d_b_h_r8 = 0; n_2d_b_r8 = 0; n_3d_b_h_r8 = 0; n_3d_b_r8 = 0; n_2d_bq_h_r8 = 0; n_2d_bq_r8 = 0; n_3d_bq_h_r8 = 0; n_3d_bq_r8 = 0
    n_2d_d_h_r8 = 0; n_2d_d_r8 = 0; n_3d_d_h_r8 = 0; n_3d_d_r8 = 0; n_2d_dq_h_r8 = 0; n_2d_dq_r8 = 0; n_3d_dq_h_r8 = 0; n_3d_dq_r8 = 0
    n_2d_u_h_r8 = 0; n_2d_u_r8 = 0; n_3d_u_h_r8 = 0; n_3d_u_r8 = 0; n_2d_uq_h_r8 = 0; n_2d_uq_r8 = 0; n_3d_uq_h_r8 = 0; n_3d_uq_r8 = 0
    n_2d_g_h_r8 = 0; n_2d_g_r8 = 0; n_3d_g_h_r8 = 0; n_3d_g_r8 = 0
                                                                    n_2d_ca_h_r8 = 0; n_2d_ca_r8 = 0; n_3d_ca_h_r8 = 0; n_3d_ca_r8 = 0
    n_2d_c_h_l  = 0; n_2d_c_l  = 0; n_2d_c_h_i4 = 0; n_2d_c_i4 = 0; n_2d_ca_h_i4 = 0; n_2d_ca_i4 = 0
    n_3d_c_h_l  = 0; n_3d_c_l  = 0; n_3d_c_h_i4 = 0; n_3d_c_i4 = 0; n_3d_ca_h_i4 = 0; n_3d_ca_i4 = 0
    do i = 1, var_stack%size
      associate (info => var_stack%var_info(i))
      select case (info%loc)
      case ('C')
        if (info%with_halo) then
          if (info%only_2d) then
            select case (info%dtype)
            case (dtype_r8)
              n_2d_c_h_r8 = n_2d_c_h_r8 + 1
              if (update_var_stack) info%array_idx = n_2d_c_h_r8
            case (dtype_i4)
              n_2d_c_h_i4 = n_2d_c_h_i4 + 1
              if (update_var_stack) info%array_idx = n_2d_c_h_i4
            case (dtype_l )
              n_2d_c_h_l  = n_2d_c_h_l  + 1
              if (update_var_stack) info%array_idx = n_2d_c_h_l
            end select
          else
            select case (info%dtype)
            case (dtype_r8)
              n_3d_c_h_r8 = n_3d_c_h_r8 + 1
              if (update_var_stack) info%array_idx = n_3d_c_h_r8
            case (dtype_i4)
              n_3d_c_h_i4 = n_3d_c_h_i4 + 1
              if (update_var_stack) info%array_idx = n_3d_c_h_i4
            case (dtype_l )
              n_3d_c_h_l  = n_3d_c_h_l  + 1
              if (update_var_stack) info%array_idx = n_3d_c_h_l
            end select
          end if
        else
          if (info%only_2d) then
            select case (info%dtype)
            case (dtype_r8)
              n_2d_c_r8 = n_2d_c_r8 + 1
              if (update_var_stack) info%array_idx = n_2d_c_r8
            case (dtype_l )
              n_2d_c_l  = n_2d_c_l  + 1
              if (update_var_stack) info%array_idx = n_2d_c_l
            end select
          else
            select case (info%dtype)
            case (dtype_r8)
              n_3d_c_r8 = n_3d_c_r8 + 1
              if (update_var_stack) info%array_idx = n_3d_c_r8
            case (dtype_l )
              n_3d_c_l  = n_3d_c_l  + 1
              if (update_var_stack) info%array_idx = n_3d_c_l
            end select
          end if
        end if
      case ('CA')
        if (info%with_halo) then
          if (info%only_2d) then
            select case (info%dtype)
            case (dtype_r8)
              n_2d_ca_h_r8 = n_2d_ca_h_r8 + 1
              if (update_var_stack) info%array_idx = n_2d_ca_h_r8
            case (dtype_i4)
              n_2d_ca_h_i4 = n_2d_ca_h_i4 + 1
              if (update_var_stack) info%array_idx = n_2d_ca_h_i4
            end select
          else
            select case (info%dtype)
            case (dtype_r8)
              n_3d_ca_h_r8 = n_3d_ca_h_r8 + 1
              if (update_var_stack) info%array_idx = n_3d_ca_h_r8
            case (dtype_i4)
              n_3d_ca_h_i4 = n_3d_ca_h_i4 + 1
              if (update_var_stack) info%array_idx = n_3d_ca_h_i4
            end select
          end if
        else
          if (info%only_2d) then
            select case (info%dtype)
            case (dtype_r8)
              n_2d_ca_r8 = n_2d_ca_r8 + 1
              if (update_var_stack) info%array_idx = n_2d_ca_r8
            case (dtype_i4)
              n_2d_ca_i4 = n_2d_ca_i4 + 1
              if (update_var_stack) info%array_idx = n_2d_ca_i4
            end select
          else
            select case (info%dtype)
            case (dtype_r8)
              n_3d_ca_r8 = n_3d_ca_r8 + 1
              if (update_var_stack) info%array_idx = n_3d_ca_r8
            case (dtype_i4)
              n_3d_ca_i4 = n_3d_ca_i4 + 1
              if (update_var_stack) info%array_idx = n_3d_ca_i4
            end select
          end if
        end if
      case ('CQ')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_cq_h_r8 = n_2d_cq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_cq_h_r8
          else
            n_3d_cq_h_r8 = n_3d_cq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_cq_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_cq_r8 = n_2d_cq_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_cq_r8
          else
            n_3d_cq_r8 = n_3d_cq_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_cq_r8
          end if
        end if
      case ('L')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_l_h_r8 = n_2d_l_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_l_h_r8
          else
            n_3d_l_h_r8 = n_3d_l_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_l_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_l_r8 = n_2d_l_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_l_r8
          else
            n_3d_l_r8 = n_3d_l_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_l_r8
          end if
        end if
      case ('LQ')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_lq_h_r8 = n_2d_lq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_lq_h_r8
          else
            n_3d_lq_h_r8 = n_3d_lq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_lq_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_lq_r8 = n_2d_lq_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_lq_r8
          else
            n_3d_lq_r8 = n_3d_lq_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_lq_r8
          end if
        end if
      case ('R')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_r_h_r8 = n_2d_r_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_r_h_r8
          else
            n_3d_r_h_r8 = n_3d_r_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_r_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_r_r8 = n_2d_r_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_r_r8
          else
            n_3d_r_r8 = n_3d_r_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_r_r8
          end if
        end if
      case ('RQ')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_rq_h_r8 = n_2d_rq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_rq_h_r8
          else
            n_3d_rq_h_r8 = n_3d_rq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_rq_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_rq_r8 = n_2d_rq_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_rq_r8
          else
            n_3d_rq_r8 = n_3d_rq_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_rq_r8
          end if
        end if
      case ('T')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_t_h_r8 = n_2d_t_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_t_h_r8
          else
            n_3d_t_h_r8 = n_3d_t_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_t_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_t_r8 = n_2d_t_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_t_r8
          else
            n_3d_t_r8 = n_3d_t_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_t_r8
          end if
        end if
      case ('TQ')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_tq_h_r8 = n_2d_tq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_tq_h_r8
          else
            n_3d_tq_h_r8 = n_3d_tq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_tq_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_tq_r8 = n_2d_tq_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_tq_r8
          else
            n_3d_tq_r8 = n_3d_tq_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_tq_r8
          end if
        end if
      case ('B')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_b_h_r8 = n_2d_b_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_b_h_r8
          else
            n_3d_b_h_r8 = n_3d_b_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_b_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_b_r8 = n_2d_b_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_b_r8
          else
            n_3d_b_r8 = n_3d_b_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_b_r8
          end if
        end if
      case ('BQ')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_bq_h_r8 = n_2d_bq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_bq_h_r8
          else
            n_3d_bq_h_r8 = n_3d_bq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_bq_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_bq_r8 = n_2d_bq_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_bq_r8
          else
            n_3d_bq_r8 = n_3d_bq_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_bq_r8
          end if
        end if
      case ('D')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_d_h_r8 = n_2d_d_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_d_h_r8
          else
            n_3d_d_h_r8 = n_3d_d_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_d_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_d_r8 = n_2d_d_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_d_r8
          else
            n_3d_d_r8 = n_3d_d_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_d_r8
          end if
        end if
      case ('DQ')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_dq_h_r8 = n_2d_dq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_dq_h_r8
          else
            n_3d_dq_h_r8 = n_3d_dq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_dq_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_dq_r8 = n_2d_dq_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_dq_r8
          else
            n_3d_dq_r8 = n_3d_dq_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_dq_r8
          end if
        end if
      case ('U')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_u_h_r8 = n_2d_u_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_u_h_r8
          else
            n_3d_u_h_r8 = n_3d_u_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_u_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_u_r8 = n_2d_u_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_u_r8
          else
            n_3d_u_r8 = n_3d_u_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_u_r8
          end if
        end if
      case ('UQ')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_uq_h_r8 = n_2d_uq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_uq_h_r8
          else
            n_3d_uq_h_r8 = n_3d_uq_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_uq_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_uq_r8 = n_2d_uq_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_uq_r8
          else
            n_3d_uq_r8 = n_3d_uq_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_uq_r8
          end if
        end if
      case ('G')
        if (info%with_halo) then
          if (info%only_2d) then
            n_2d_g_h_r8 = n_2d_g_h_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_g_h_r8
          else
            n_3d_g_h_r8 = n_3d_g_h_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_g_h_r8
          end if
        else
          if (info%only_2d) then
            n_2d_g_r8 = n_2d_g_r8 + 1
            if (update_var_stack) info%array_idx = n_2d_g_r8
          else
            n_3d_g_r8 = n_3d_g_r8 + 1
            if (update_var_stack) info%array_idx = n_3d_g_r8
          end if
        end if
      end select
      end associate
    end do

    associate (ims => this%domain%ims, ime => this%domain%ime, &
               ids => this%domain%ids, ide => this%domain%ide, &
               jms => this%domain%jms, jme => this%domain%jme, &
               jds => this%domain%jds, jde => this%domain%jde, &
               kms => this%domain%kms, kme => this%domain%kme, &
               kds => this%domain%kds, kde => this%domain%kde, &
               pqs => this%domain%pqs, pqe => this%domain%pqe, &
               pgs => this%domain%pgs, pge => this%domain%pge  )
    ! Center
    if (n_2d_c_h_r8 > 0) then
      allocate(this%a_2d_c_h_r8(ims:ime,jms:jme,n_2d_c_h_r8))
      this%a_2d_c_h_r8 = 0
    end if
    if (n_2d_c_l  > 0) then
      allocate(this%a_2d_c_l (ids:ide,jds:jde,n_2d_c_l ))
      this%a_2d_c_l  = .false.
    end if
    if (n_2d_c_h_l  > 0) then
      allocate(this%a_2d_c_h_l (ims:ime,jms:jme,n_2d_c_h_l ))
      this%a_2d_c_h_l  = .false.
    end if
    if (n_2d_c_h_i4 > 0) then
      allocate(this%a_2d_c_h_i4(ims:ime,jms:jme,n_2d_c_h_i4))
      this%a_2d_c_h_i4 = 0
    end if
    if (n_2d_c_i4 > 0) then
      allocate(this%a_2d_c_i4(ids:ide,jds:jde,n_2d_c_i4))
      this%a_2d_c_i4 = 0
    end if
    if (n_3d_c_h_r8 > 0) then
      allocate(this%a_3d_c_h_r8(ims:ime,jms:jme,kms:kme,n_3d_c_h_r8))
      this%a_3d_c_h_r8 = 0
    end if
    if (n_3d_c_l  > 0) then
      allocate(this%a_3d_c_l (ids:ide,jds:jde,kds:kde,n_3d_c_l ))
      this%a_3d_c_l  = .false.
    end if
    if (n_3d_c_h_l  > 0) then
      allocate(this%a_3d_c_h_l (ims:ime,jms:jme,kms:kme,n_3d_c_h_l ))
      this%a_3d_c_h_l  = .false.
    end if
    if (n_3d_c_h_i4 > 0) then
      allocate(this%a_3d_c_h_i4(ims:ime,jms:jme,kms:kme,n_3d_c_h_i4))
      this%a_3d_c_h_i4 = 0
    end if
    if (n_3d_c_i4 > 0) then
      allocate(this%a_3d_c_i4(ims:ime,jms:jme,kms:kme,n_3d_c_i4))
      this%a_3d_c_i4 = 0
    end if
    if (n_2d_c_r8 > 0) then
      allocate(this%a_2d_c_r8(ids:ide,jds:jde,n_2d_c_r8))
      this%a_2d_c_r8 = 0
    end if
    if (n_3d_c_r8 > 0) then
      allocate(this%a_3d_c_r8(ids:ide,jds:jde,kms:kme,n_3d_c_r8))
      this%a_3d_c_r8 = 0
    end if
    ! Cell Average
    if (n_2d_ca_h_r8 > 0) then
      allocate(this%a_2d_ca_h_r8(ims:ime,jms:jme,n_2d_ca_h_r8))
      this%a_2d_ca_h_r8 = 0
    end if
    if (n_2d_ca_h_i4 > 0) then
      allocate(this%a_2d_ca_h_i4(ims:ime,jms:jme,n_2d_ca_h_i4))
      this%a_2d_ca_h_i4 = 0
    end if
    if (n_2d_ca_i4 > 0) then
      allocate(this%a_2d_ca_i4(ids:ide,jds:jde,n_2d_ca_i4))
      this%a_2d_ca_i4 = 0
    end if
    if (n_3d_ca_h_r8 > 0) then
      allocate(this%a_3d_ca_h_r8(ims:ime,jms:jme,kms:kme,n_3d_ca_h_r8))
      this%a_3d_ca_h_r8 = 0
    end if
    if (n_3d_ca_h_i4 > 0) then
      allocate(this%a_3d_ca_h_i4(ims:ime,jms:jme,kms:kme,n_3d_ca_h_i4))
      this%a_3d_ca_h_i4 = 0
    end if
    if (n_3d_ca_i4 > 0) then
      allocate(this%a_3d_ca_i4(ids:ide,jds:jde,kds:kde,n_3d_ca_i4))
      this%a_3d_ca_i4 = 0
    end if
    if (n_2d_ca_r8 > 0) then
      allocate(this%a_2d_ca_r8(ids:ide,jds:jde,n_2d_ca_r8))
      this%a_2d_ca_r8 = 0
    end if
    if (n_3d_ca_r8 > 0) then
      allocate(this%a_3d_ca_r8(ids:ide,jds:jde,kms:kme,n_3d_ca_r8))
      this%a_3d_ca_r8 = 0
    end if
    ! Cell quadrature
    if (n_2d_cq_h_r8 > 0) then
      allocate(this%a_2d_cq_h_r8(pqs:pqe,ims:ime,jms:jme,n_2d_cq_h_r8))
      this%a_2d_cq_h_r8 = 0
    end if
    if (n_3d_cq_h_r8 > 0) then
      allocate(this%a_3d_cq_h_r8(pqs:pqe,ims:ime,jms:jme,kms:kme,n_3d_cq_h_r8))
      this%a_3d_cq_h_r8 = 0
    end if
    if (n_2d_cq_r8 > 0) then
      allocate(this%a_2d_cq_r8(pqs:pqe,ids:ide,jds:jde,n_2d_cq_r8))
      this%a_2d_cq_r8 = 0
    end if
    if (n_3d_cq_r8 > 0) then
      allocate(this%a_3d_cq_r8(pqs:pqe,ids:ide,jds:jde,kms:kme,n_3d_cq_r8))
      this%a_3d_cq_r8 = 0
    end if
    ! Left cell edge quadtrature
    if (n_2d_l_h_r8 > 0) then
      allocate(this%a_2d_l_h_r8(ims:ime,jms:jme,n_2d_l_h_r8))
      this%a_2d_l_h_r8 = 0
    end if
    if (n_3d_l_h_r8 > 0) then
      allocate(this%a_3d_l_h_r8(ims:ime,jms:jme,kms:kme,n_3d_l_h_r8))
      this%a_3d_l_h_r8 = 0
    end if
    if (n_2d_l_r8 > 0) then
      allocate(this%a_2d_l_r8(ids:ide+1,jds:jde,n_2d_l_r8))
      this%a_2d_l_r8 = 0
    end if
    if (n_3d_l_r8 > 0) then
      allocate(this%a_3d_l_r8(ids:ide+1,jds:jde,kms:kme,n_3d_l_r8))
      this%a_3d_l_r8 = 0
    end if
    pes = this%domain%pes(1)
    pee = this%domain%pee(1)
    if (n_2d_lq_h_r8 > 0) then
      allocate(this%a_2d_lq_h_r8(pes:pee,ims:ime,jms:jme,n_2d_lq_h_r8))
      this%a_2d_lq_h_r8 = 0
    end if
    if (n_3d_lq_h_r8 > 0) then
      allocate(this%a_3d_lq_h_r8(pes:pee,ims:ime,jms:jme,kms:kme,n_3d_lq_h_r8))
      this%a_3d_lq_h_r8 = 0
    end if
    if (n_2d_lq_r8 > 0) then
      allocate(this%a_2d_lq_r8(pes:pee,ids:ide+1,jds:jde,n_2d_lq_r8))
      this%a_2d_lq_r8 = 0
    end if
    if (n_3d_lq_r8 > 0) then
      allocate(this%a_3d_lq_r8(pes:pee,ids:ide+1,jds:jde,kms:kme,n_3d_lq_r8))
      this%a_3d_lq_r8 = 0
    end if
    ! Right cell edge quadtrature
    if (n_2d_r_h_r8 > 0) then
      allocate(this%a_2d_r_h_r8(ims:ime,jms:jme,n_2d_r_h_r8))
      this%a_2d_r_h_r8 = 0
    end if
    if (n_3d_r_h_r8 > 0) then
      allocate(this%a_3d_r_h_r8(ims:ime,jms:jme,kms:kme,n_3d_r_h_r8))
      this%a_3d_r_h_r8 = 0
    end if
    if (n_2d_r_r8 > 0) then
      allocate(this%a_2d_r_r8(ids:ide+1,jds:jde,n_2d_r_r8))
      this%a_2d_r_r8 = 0
    end if
    if (n_3d_r_r8 > 0) then
      allocate(this%a_3d_r_r8(ids:ide+1,jds:jde,kms:kme,n_3d_r_r8))
      this%a_3d_r_r8 = 0
    end if
    pes = this%domain%pes(2)
    pee = this%domain%pee(2)
    if (n_2d_rq_h_r8 > 0) then
      allocate(this%a_2d_rq_h_r8(pes:pee,ims:ime,jms:jme,n_2d_rq_h_r8))
      this%a_2d_rq_h_r8 = 0
    end if
    if (n_3d_rq_h_r8 > 0) then
      allocate(this%a_3d_rq_h_r8(pes:pee,ims:ime,jms:jme,kms:kme,n_3d_rq_h_r8))
      this%a_3d_rq_h_r8 = 0
    end if
    if (n_2d_rq_r8 > 0) then
      allocate(this%a_2d_rq_r8(pes:pee,ids:ide+1,jds:jde,n_2d_rq_r8))
      this%a_2d_rq_r8 = 0
    end if
    if (n_3d_rq_r8 > 0) then
      allocate(this%a_3d_rq_r8(pes:pee,ids:ide+1,jds:jde,kms:kme,n_3d_rq_r8))
      this%a_3d_rq_r8 = 0
    end if
    ! Bottom cell edge quadtrature
    if (n_2d_b_h_r8 > 0) then
      allocate(this%a_2d_b_h_r8(ims:ime,jms:jme,n_2d_b_h_r8))
      this%a_2d_b_h_r8 = 0
    end if
    if (n_3d_b_h_r8 > 0) then
      allocate(this%a_3d_b_h_r8(ims:ime,jms:jme,kms:kme,n_3d_b_h_r8))
      this%a_3d_b_h_r8 = 0
    end if
    if (n_2d_b_r8 > 0) then
      allocate(this%a_2d_b_r8(ids:ide,jds:jde+1,n_2d_b_r8))
      this%a_2d_b_r8 = 0
    end if
    if (n_3d_b_r8 > 0) then
      allocate(this%a_3d_b_r8(ids:ide,jds:jde+1,kms:kme,n_3d_b_r8))
      this%a_3d_b_r8 = 0
    end if
    pes = this%domain%pes(3)
    pee = this%domain%pee(3)
    if (n_2d_bq_h_r8 > 0) then
      allocate(this%a_2d_bq_h_r8(pes:pee,ims:ime,jms:jme,n_2d_bq_h_r8))
      this%a_2d_bq_h_r8 = 0
    end if
    if (n_3d_bq_h_r8 > 0) then
      allocate(this%a_3d_bq_h_r8(pes:pee,ims:ime,jms:jme,kms:kme,n_3d_bq_h_r8))
      this%a_3d_bq_h_r8 = 0
    end if
    if (n_2d_bq_r8 > 0) then
      allocate(this%a_2d_bq_r8(pes:pee,ids:ide,jds:jde+1,n_2d_bq_r8))
      this%a_2d_bq_r8 = 0
    end if
    if (n_3d_bq_r8 > 0) then
      allocate(this%a_3d_bq_r8(pes:pee,ids:ide,jds:jde+1,kms:kme,n_3d_bq_r8))
      this%a_3d_bq_r8 = 0
    end if
    ! Top cell edge quadtrature
    if (n_2d_t_h_r8 > 0) then
      allocate(this%a_2d_t_h_r8(ims:ime,jms:jme,n_2d_t_h_r8))
      this%a_2d_t_h_r8 = 0
    end if
    if (n_3d_t_h_r8 > 0) then
      allocate(this%a_3d_t_h_r8(ims:ime,jms:jme,kms:kme,n_3d_t_h_r8))
      this%a_3d_t_h_r8 = 0
    end if
    if (n_2d_t_r8 > 0) then
      allocate(this%a_2d_t_r8(ids:ide,jds:jde+1,n_2d_t_r8))
      this%a_2d_t_r8 = 0
    end if
    if (n_3d_t_r8 > 0) then
      allocate(this%a_3d_t_r8(ids:ide,jds:jde+1,kms:kme,n_3d_t_r8))
      this%a_3d_t_r8 = 0
    end if
    pes = this%domain%pes(4)
    pee = this%domain%pee(4)
    if (n_2d_tq_h_r8 > 0) then
      allocate(this%a_2d_tq_h_r8(pes:pee,ims:ime,jms:jme,n_2d_tq_h_r8))
      this%a_2d_tq_h_r8 = 0
    end if
    if (n_3d_tq_h_r8 > 0) then
      allocate(this%a_3d_tq_h_r8(pes:pee,ims:ime,jms:jme,kms:kme,n_3d_tq_h_r8))
      this%a_3d_tq_h_r8 = 0
    end if
    if (n_2d_tq_r8 > 0) then
      allocate(this%a_2d_tq_r8(pes:pee,ids:ide,jds:jde+1,n_2d_tq_r8))
      this%a_2d_tq_r8 = 0
    end if
    if (n_3d_tq_r8 > 0) then
      allocate(this%a_3d_tq_r8(pes:pee,ids:ide,jds:jde+1,kms:kme,n_3d_tq_r8))
      this%a_3d_tq_r8 = 0
    end if
    ! Down cell edge quadtrature
    if (n_2d_d_h_r8 > 0) then
      allocate(this%a_2d_d_h_r8(ims:ime,jms:jme,n_2d_d_h_r8))
      this%a_2d_d_h_r8 = 0
    end if
    if (n_2d_d_r8 > 0) then
      allocate(this%a_2d_d_r8(ids:ide,jds:jde,n_2d_d_r8))
      this%a_2d_d_r8 = 0
    end if
    if (n_3d_d_h_r8 > 0) then
      allocate(this%a_3d_d_h_r8(ims:ime,jms:jme,kms:kme+1,n_3d_d_h_r8))
      this%a_3d_d_h_r8 = 0
    end if
    if (n_3d_d_r8 > 0) then
      allocate(this%a_3d_d_r8(ids:ide,jds:jde,kms:kme+1,n_3d_d_r8))
      this%a_3d_d_r8 = 0
    end if
    pes = this%domain%pes(5)
    pee = this%domain%pee(5)
    if (n_2d_dq_h_r8 > 0) then
      allocate(this%a_2d_dq_h_r8(pes:pee,ims:ime,jms:jme,n_2d_dq_h_r8))
      this%a_2d_dq_h_r8 = 0
    end if
    if (n_2d_dq_r8 > 0) then
      allocate(this%a_2d_dq_r8(pes:pee,ids:ide,jds:jde,n_2d_dq_r8))
      this%a_2d_dq_r8 = 0
    end if
    if (n_3d_dq_h_r8 > 0) then
      allocate(this%a_3d_dq_h_r8(pes:pee,ims:ime,jms:jme,kms:kme+1,n_3d_dq_h_r8))
      this%a_3d_dq_h_r8 = 0
    end if
    if (n_3d_dq_r8 > 0) then
      allocate(this%a_3d_dq_r8(pes:pee,ids:ide,jds:jde,kms:kme+1,n_3d_dq_r8))
      this%a_3d_dq_r8 = 0
    end if
    ! Up cell edge quadtrature
    if (n_2d_u_h_r8 > 0) then
      allocate(this%a_2d_u_h_r8(ims:ime,jms:jme,n_2d_u_h_r8))
      this%a_2d_u_h_r8 = 0
    end if
    if (n_2d_u_r8 > 0) then
      allocate(this%a_2d_u_r8(ids:ide,jds:jde,n_2d_u_r8))
      this%a_2d_u_r8 = 0
    end if
    if (n_3d_u_h_r8 > 0) then
      allocate(this%a_3d_u_h_r8(ims:ime,jms:jme,kms:kme+1,n_3d_u_h_r8))
      this%a_3d_u_h_r8 = 0
    end if
    if (n_3d_u_r8 > 0) then
      allocate(this%a_3d_u_r8(ids:ide,jds:jde,kms:kme+1,n_3d_u_r8))
      this%a_3d_u_r8 = 0
    end if
    pes = this%domain%pes(6)
    pee = this%domain%pee(6)
    if (n_2d_uq_h_r8 > 0) then
      allocate(this%a_2d_uq_h_r8(pes:pee,ims:ime,jms:jme,n_2d_uq_h_r8))
      this%a_2d_uq_h_r8 = 0
    end if
    if (n_2d_uq_r8 > 0) then
      allocate(this%a_2d_uq_r8(pes:pee,ids:ide,jds:jde,n_2d_uq_r8))
      this%a_2d_uq_r8 = 0
    end if
    if (n_3d_uq_h_r8 > 0) then
      allocate(this%a_3d_uq_h_r8(pes:pee,ims:ime,jms:jme,kms:kme+1,n_3d_uq_h_r8))
      this%a_3d_uq_h_r8 = 0
    end if
    if (n_3d_uq_r8 > 0) then
      allocate(this%a_3d_uq_r8(pes:pee,ids:ide,jds:jde,kms:kme+1,n_3d_uq_r8))
      this%a_3d_uq_r8 = 0
    end if
    ! Ghost point
    if (n_2d_g_r8 > 0) then
      allocate(this%a_2d_g_r8(pgs:pge,ids:ide,jds:jde,n_2d_g_r8))
      this%a_2d_g_r8 = 0
    end if
    if (n_2d_g_h_r8 > 0) then
      allocate(this%a_2d_g_h_r8(pgs:pge,ims:ime,jms:jme,n_2d_g_h_r8))
      this%a_2d_g_h_r8 = 0
    end if
    if (n_3d_g_r8 > 0) then
      allocate(this%a_3d_g_r8(pgs:pge,ids:ide,jds:jde,kms:kme,n_3d_g_r8))
      this%a_3d_g_r8 = 0
    end if
    if (n_3d_g_h_r8 > 0) then
      allocate(this%a_3d_g_h_r8(pgs:pge,ims:ime,jms:jme,kms:kme,n_3d_g_h_r8))
      this%a_3d_g_h_r8 = 0
    end if
    end associate

  end subroutine cubed_sphere_domain_array_allocate_arrays

  subroutine cubed_sphere_domain_array_get_array_2d_r8(this, ptr, var_info)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    real(r8)           , intent(out), pointer                 :: ptr(:,:)
    type(var_info_type), intent(in )                          :: var_info

    select case (var_info%loc)
    case ('C')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_c_h_r8, 1):ubound(this%a_2d_c_h_r8, 1), &
            lbound(this%a_2d_c_h_r8, 2):ubound(this%a_2d_c_h_r8, 2)) => this%a_2d_c_h_r8(:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_c_r8  , 1):ubound(this%a_2d_c_r8  , 1), &
            lbound(this%a_2d_c_r8  , 2):ubound(this%a_2d_c_r8  , 2)) => this%a_2d_c_r8  (:,:,var_info%array_idx)
      end if
    case ('CA')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_ca_h_r8, 1):ubound(this%a_2d_ca_h_r8, 1), &
            lbound(this%a_2d_ca_h_r8, 2):ubound(this%a_2d_ca_h_r8, 2)) => this%a_2d_ca_h_r8(:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_ca_r8  , 1):ubound(this%a_2d_ca_r8  , 1), &
            lbound(this%a_2d_ca_r8  , 2):ubound(this%a_2d_ca_r8  , 2)) => this%a_2d_ca_r8  (:,:,var_info%array_idx)
      end if
    case ('L')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_l_h_r8, 1):ubound(this%a_2d_l_h_r8, 1), &
            lbound(this%a_2d_l_h_r8, 2):ubound(this%a_2d_l_h_r8, 2)) => this%a_2d_l_h_r8(:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_l_r8  , 1):ubound(this%a_2d_l_r8  , 1), &
            lbound(this%a_2d_l_r8  , 2):ubound(this%a_2d_l_r8  , 2)) => this%a_2d_l_r8  (:,:,var_info%array_idx)
      end if
    case ('R')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_r_h_r8, 1):ubound(this%a_2d_r_h_r8, 1), &
            lbound(this%a_2d_r_h_r8, 2):ubound(this%a_2d_r_h_r8, 2)) => this%a_2d_r_h_r8(:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_r_r8  , 1):ubound(this%a_2d_r_r8  , 1), &
            lbound(this%a_2d_r_r8  , 2):ubound(this%a_2d_r_r8  , 2)) => this%a_2d_r_r8  (:,:,var_info%array_idx)
      end if
    case ('B')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_b_h_r8, 1):ubound(this%a_2d_b_h_r8, 1), &
            lbound(this%a_2d_b_h_r8, 2):ubound(this%a_2d_b_h_r8, 2)) => this%a_2d_b_h_r8(:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_b_r8  , 1):ubound(this%a_2d_b_r8  , 1), &
            lbound(this%a_2d_b_r8  , 2):ubound(this%a_2d_b_r8  , 2)) => this%a_2d_b_r8  (:,:,var_info%array_idx)
      end if
    case ('T')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_t_h_r8, 1):ubound(this%a_2d_t_h_r8, 1), &
            lbound(this%a_2d_t_h_r8, 2):ubound(this%a_2d_t_h_r8, 2)) => this%a_2d_t_h_r8(:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_t_r8  , 1):ubound(this%a_2d_t_r8  , 1), &
            lbound(this%a_2d_t_r8  , 2):ubound(this%a_2d_t_r8  , 2)) => this%a_2d_t_r8  (:,:,var_info%array_idx)
      end if
    case default
      nullify(ptr)
    end select

  end subroutine cubed_sphere_domain_array_get_array_2d_r8

  subroutine cubed_sphere_domain_array_get_array_3d_r8_1(this, ptr, var_info)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    real(r8)           , intent(out), pointer                 :: ptr(:,:,:)
    type(var_info_type), intent(in )                          :: var_info

    select case (var_info%loc)
    case ('C')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_c_h_r8, 1):ubound(this%a_3d_c_h_r8, 1), &
            lbound(this%a_3d_c_h_r8, 2):ubound(this%a_3d_c_h_r8, 2), &
            lbound(this%a_3d_c_h_r8, 3):ubound(this%a_3d_c_h_r8, 3)) => this%a_3d_c_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_c_r8  , 1):ubound(this%a_3d_c_r8  , 1), &
            lbound(this%a_3d_c_r8  , 2):ubound(this%a_3d_c_r8  , 2), &
            lbound(this%a_3d_c_r8  , 3):ubound(this%a_3d_c_r8  , 3)) => this%a_3d_c_r8  (:,:,:,var_info%array_idx)
      end if
    case ('CA')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_ca_h_r8, 1):ubound(this%a_3d_ca_h_r8, 1), &
            lbound(this%a_3d_ca_h_r8, 2):ubound(this%a_3d_ca_h_r8, 2), &
            lbound(this%a_3d_ca_h_r8, 3):ubound(this%a_3d_ca_h_r8, 3)) => this%a_3d_ca_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_ca_r8  , 1):ubound(this%a_3d_ca_r8  , 1), &
            lbound(this%a_3d_ca_r8  , 2):ubound(this%a_3d_ca_r8  , 2), &
            lbound(this%a_3d_ca_r8  , 3):ubound(this%a_3d_ca_r8  , 3)) => this%a_3d_ca_r8  (:,:,:,var_info%array_idx)
      end if
    case ('CQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_cq_h_r8, 1):ubound(this%a_2d_cq_h_r8, 1), &
            lbound(this%a_2d_cq_h_r8, 2):ubound(this%a_2d_cq_h_r8, 2), &
            lbound(this%a_2d_cq_h_r8, 3):ubound(this%a_2d_cq_h_r8, 3)) => this%a_2d_cq_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_cq_r8  , 1):ubound(this%a_2d_cq_r8  , 1), &
            lbound(this%a_2d_cq_r8  , 2):ubound(this%a_2d_cq_r8  , 2), &
            lbound(this%a_2d_cq_r8  , 3):ubound(this%a_2d_cq_r8  , 3)) => this%a_2d_cq_r8  (:,:,:,var_info%array_idx)
      end if
    case ('L')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_l_h_r8, 1):ubound(this%a_3d_l_h_r8, 1), &
            lbound(this%a_3d_l_h_r8, 2):ubound(this%a_3d_l_h_r8, 2), &
            lbound(this%a_3d_l_h_r8, 3):ubound(this%a_3d_l_h_r8, 3)) => this%a_3d_l_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_l_r8  , 1):ubound(this%a_3d_l_r8  , 1), &
            lbound(this%a_3d_l_r8  , 2):ubound(this%a_3d_l_r8  , 2), &
            lbound(this%a_3d_l_r8  , 3):ubound(this%a_3d_l_r8  , 3)) => this%a_3d_l_r8  (:,:,:,var_info%array_idx)
      end if
    case ('LQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_lq_h_r8, 1):ubound(this%a_2d_lq_h_r8, 1), &
            lbound(this%a_2d_lq_h_r8, 2):ubound(this%a_2d_lq_h_r8, 2), &
            lbound(this%a_2d_lq_h_r8, 3):ubound(this%a_2d_lq_h_r8, 3)) => this%a_2d_lq_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_lq_r8  , 1):ubound(this%a_2d_lq_r8  , 1), &
            lbound(this%a_2d_lq_r8  , 2):ubound(this%a_2d_lq_r8  , 2), &
            lbound(this%a_2d_lq_r8  , 3):ubound(this%a_2d_lq_r8  , 3)) => this%a_2d_lq_r8  (:,:,:,var_info%array_idx)
      end if
    case ('R')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_r_h_r8, 1):ubound(this%a_3d_r_h_r8, 1), &
            lbound(this%a_3d_r_h_r8, 2):ubound(this%a_3d_r_h_r8, 2), &
            lbound(this%a_3d_r_h_r8, 3):ubound(this%a_3d_r_h_r8, 3)) => this%a_3d_r_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_r_r8  , 1):ubound(this%a_3d_r_r8  , 1), &
            lbound(this%a_3d_r_r8  , 2):ubound(this%a_3d_r_r8  , 2), &
            lbound(this%a_3d_r_r8  , 3):ubound(this%a_3d_r_r8  , 3)) => this%a_3d_r_r8  (:,:,:,var_info%array_idx)
      end if
    case ('RQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_rq_h_r8, 1):ubound(this%a_2d_rq_h_r8, 1), &
            lbound(this%a_2d_rq_h_r8, 2):ubound(this%a_2d_rq_h_r8, 2), &
            lbound(this%a_2d_rq_h_r8, 3):ubound(this%a_2d_rq_h_r8, 3)) => this%a_2d_rq_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_rq_r8  , 1):ubound(this%a_2d_rq_r8  , 1), &
            lbound(this%a_2d_rq_r8  , 2):ubound(this%a_2d_rq_r8  , 2), &
            lbound(this%a_2d_rq_r8  , 3):ubound(this%a_2d_rq_r8  , 3)) => this%a_2d_rq_r8  (:,:,:,var_info%array_idx)
      end if
    case ('B')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_b_h_r8, 1):ubound(this%a_3d_b_h_r8, 1), &
            lbound(this%a_3d_b_h_r8, 2):ubound(this%a_3d_b_h_r8, 2), &
            lbound(this%a_3d_b_h_r8, 3):ubound(this%a_3d_b_h_r8, 3)) => this%a_3d_b_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_b_r8  , 1):ubound(this%a_3d_b_r8  , 1), &
            lbound(this%a_3d_b_r8  , 2):ubound(this%a_3d_b_r8  , 2), &
            lbound(this%a_3d_b_r8  , 3):ubound(this%a_3d_b_r8  , 3)) => this%a_3d_b_r8  (:,:,:,var_info%array_idx)
      end if
    case ('BQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_bq_h_r8, 1):ubound(this%a_2d_bq_h_r8, 1), &
            lbound(this%a_2d_bq_h_r8, 2):ubound(this%a_2d_bq_h_r8, 2), &
            lbound(this%a_2d_bq_h_r8, 3):ubound(this%a_2d_bq_h_r8, 3)) => this%a_2d_bq_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_bq_r8  , 1):ubound(this%a_2d_bq_r8  , 1), &
            lbound(this%a_2d_bq_r8  , 2):ubound(this%a_2d_bq_r8  , 2), &
            lbound(this%a_2d_bq_r8  , 3):ubound(this%a_2d_bq_r8  , 3)) => this%a_2d_bq_r8  (:,:,:,var_info%array_idx)
      end if
    case ('T')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_t_h_r8, 1):ubound(this%a_3d_t_h_r8, 1), &
            lbound(this%a_3d_t_h_r8, 2):ubound(this%a_3d_t_h_r8, 2), &
            lbound(this%a_3d_t_h_r8, 3):ubound(this%a_3d_t_h_r8, 3)) => this%a_3d_t_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_t_r8  , 1):ubound(this%a_3d_t_r8  , 1), &
            lbound(this%a_3d_t_r8  , 2):ubound(this%a_3d_t_r8  , 2), &
            lbound(this%a_3d_t_r8  , 3):ubound(this%a_3d_t_r8  , 3)) => this%a_3d_t_r8  (:,:,:,var_info%array_idx)
      end if
    case ('TQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_tq_h_r8, 1):ubound(this%a_2d_tq_h_r8, 1), &
            lbound(this%a_2d_tq_h_r8, 2):ubound(this%a_2d_tq_h_r8, 2), &
            lbound(this%a_2d_tq_h_r8, 3):ubound(this%a_2d_tq_h_r8, 3)) => this%a_2d_tq_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_tq_r8  , 1):ubound(this%a_2d_tq_r8  , 1), &
            lbound(this%a_2d_tq_r8  , 2):ubound(this%a_2d_tq_r8  , 2), &
            lbound(this%a_2d_tq_r8  , 3):ubound(this%a_2d_tq_r8  , 3)) => this%a_2d_tq_r8  (:,:,:,var_info%array_idx)
      end if
    case ('D')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_d_h_r8, 1):ubound(this%a_3d_d_h_r8, 1), &
            lbound(this%a_3d_d_h_r8, 2):ubound(this%a_3d_d_h_r8, 2), &
            lbound(this%a_3d_d_h_r8, 3):ubound(this%a_3d_d_h_r8, 3)) => this%a_3d_d_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_d_r8  , 1):ubound(this%a_3d_d_r8  , 1), &
            lbound(this%a_3d_d_r8  , 2):ubound(this%a_3d_d_r8  , 2), &
            lbound(this%a_3d_d_r8  , 3):ubound(this%a_3d_d_r8  , 3)) => this%a_3d_d_r8  (:,:,:,var_info%array_idx)
      end if
    case ('DQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_dq_h_r8, 1):ubound(this%a_2d_dq_h_r8, 1), &
            lbound(this%a_2d_dq_h_r8, 2):ubound(this%a_2d_dq_h_r8, 2), &
            lbound(this%a_2d_dq_h_r8, 3):ubound(this%a_2d_dq_h_r8, 3)) => this%a_2d_dq_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_dq_r8  , 1):ubound(this%a_2d_dq_r8  , 1), &
            lbound(this%a_2d_dq_r8  , 2):ubound(this%a_2d_dq_r8  , 2), &
            lbound(this%a_2d_dq_r8  , 3):ubound(this%a_2d_dq_r8  , 3)) => this%a_2d_dq_r8  (:,:,:,var_info%array_idx)
      end if
    case ('U')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_u_h_r8, 1):ubound(this%a_3d_u_h_r8, 1), &
            lbound(this%a_3d_u_h_r8, 2):ubound(this%a_3d_u_h_r8, 2), &
            lbound(this%a_3d_u_h_r8, 3):ubound(this%a_3d_u_h_r8, 3)) => this%a_3d_u_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_u_r8  , 1):ubound(this%a_3d_u_r8  , 1), &
            lbound(this%a_3d_u_r8  , 2):ubound(this%a_3d_u_r8  , 2), &
            lbound(this%a_3d_u_r8  , 3):ubound(this%a_3d_u_r8  , 3)) => this%a_3d_u_r8  (:,:,:,var_info%array_idx)
      end if
    case ('UQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_uq_h_r8, 1):ubound(this%a_2d_uq_h_r8, 1), &
            lbound(this%a_2d_uq_h_r8, 2):ubound(this%a_2d_uq_h_r8, 2), &
            lbound(this%a_2d_uq_h_r8, 3):ubound(this%a_2d_uq_h_r8, 3)) => this%a_2d_uq_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_uq_r8  , 1):ubound(this%a_2d_uq_r8  , 1), &
            lbound(this%a_2d_uq_r8  , 2):ubound(this%a_2d_uq_r8  , 2), &
            lbound(this%a_2d_uq_r8  , 3):ubound(this%a_2d_uq_r8  , 3)) => this%a_2d_uq_r8  (:,:,:,var_info%array_idx)
      end if
    case ('G')
      if (var_info%with_halo) then
        ptr(lbound(this%a_2d_g_h_r8, 1):ubound(this%a_2d_g_h_r8, 1), &
            lbound(this%a_2d_g_h_r8, 2):ubound(this%a_2d_g_h_r8, 2), &
            lbound(this%a_2d_g_h_r8, 3):ubound(this%a_2d_g_h_r8, 3)) => this%a_2d_g_h_r8(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_g_r8  , 1):ubound(this%a_2d_g_r8  , 1), &
            lbound(this%a_2d_g_r8  , 2):ubound(this%a_2d_g_r8  , 2), &
            lbound(this%a_2d_g_r8  , 3):ubound(this%a_2d_g_r8  , 3)) => this%a_2d_g_r8  (:,:,:,var_info%array_idx)
      end if
    case default
      nullify(ptr)
      stop 'Unknown location in cubed_sphere_domain_array_get_array_3d_r8_1'
    end select

  end subroutine cubed_sphere_domain_array_get_array_3d_r8_1

  subroutine cubed_sphere_domain_array_get_array_3d_r8_2(this, ptr, loc, with_halo, is, ie)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    real(r8)    , intent(out), pointer                        :: ptr(:,:,:)
    character(*), intent(in )                                 :: loc
    logical     , intent(in )                                 :: with_halo
    integer     , intent(in )                                 :: is
    integer     , intent(in )                                 :: ie

    select case (loc)
    case ('C')
      if (with_halo) then
        ptr(lbound(this%a_2d_c_h_r8, 1):ubound(this%a_2d_c_h_r8, 1), &
            lbound(this%a_2d_c_h_r8, 2):ubound(this%a_2d_c_h_r8, 2), &
            1:ie-is+1) => this%a_2d_c_h_r8(:,:,is:ie)
      else
        ptr(lbound(this%a_2d_c_r8  , 1):ubound(this%a_2d_c_r8  , 1), &
            lbound(this%a_2d_c_r8  , 2):ubound(this%a_2d_c_r8  , 2), &
            1:ie-is+1) => this%a_2d_c_r8  (:,:,is:ie)
      end if
    case ('CA')
      if (with_halo) then
        ptr(lbound(this%a_2d_ca_h_r8, 1):ubound(this%a_2d_ca_h_r8, 1), &
            lbound(this%a_2d_ca_h_r8, 2):ubound(this%a_2d_ca_h_r8, 2), &
            1:ie-is+1) => this%a_2d_ca_h_r8(:,:,is:ie)
      else
        ptr(lbound(this%a_2d_ca_r8  , 1):ubound(this%a_2d_ca_r8  , 1), &
            lbound(this%a_2d_ca_r8  , 2):ubound(this%a_2d_ca_r8  , 2), &
            1:ie-is+1) => this%a_2d_ca_r8  (:,:,is:ie)
      end if
    case ('L')
      if (with_halo) then
        ptr(lbound(this%a_2d_l_h_r8, 1):ubound(this%a_2d_l_h_r8, 1), &
            lbound(this%a_2d_l_h_r8, 2):ubound(this%a_2d_l_h_r8, 2), &
            1:ie-is+1) => this%a_2d_l_h_r8(:,:,is:ie)
      else
        ptr(lbound(this%a_2d_l_r8  , 1):ubound(this%a_2d_l_r8  , 1), &
            lbound(this%a_2d_l_r8  , 2):ubound(this%a_2d_l_r8  , 2), &
            1:ie-is+1) => this%a_2d_l_r8  (:,:,is:ie)
      end if
    case ('R')
      if (with_halo) then
        ptr(lbound(this%a_2d_r_h_r8, 1):ubound(this%a_2d_r_h_r8, 1), &
            lbound(this%a_2d_r_h_r8, 2):ubound(this%a_2d_r_h_r8, 2), &
            1:ie-is+1) => this%a_2d_r_h_r8(:,:,is:ie)
      else
        ptr(lbound(this%a_2d_r_r8  , 1):ubound(this%a_2d_r_r8  , 1), &
            lbound(this%a_2d_r_r8  , 2):ubound(this%a_2d_r_r8  , 2), &
            1:ie-is+1) => this%a_2d_r_r8  (:,:,is:ie)
      end if
    case ('B')
      if (with_halo) then
        ptr(lbound(this%a_2d_b_h_r8, 1):ubound(this%a_2d_b_h_r8, 1), &
            lbound(this%a_2d_b_h_r8, 2):ubound(this%a_2d_b_h_r8, 2), &
            1:ie-is+1) => this%a_2d_b_h_r8(:,:,is:ie)
      else
        ptr(lbound(this%a_2d_b_r8  , 1):ubound(this%a_2d_b_r8  , 1), &
            lbound(this%a_2d_b_r8  , 2):ubound(this%a_2d_b_r8  , 2), &
            1:ie-is+1) => this%a_2d_b_r8  (:,:,is:ie)
      end if
    case ('T')
      if (with_halo) then
        ptr(lbound(this%a_2d_t_h_r8, 1):ubound(this%a_2d_t_h_r8, 1), &
            lbound(this%a_2d_t_h_r8, 2):ubound(this%a_2d_t_h_r8, 2), &
            1:ie-is+1) => this%a_2d_t_h_r8(:,:,is:ie)
      else
        ptr(lbound(this%a_2d_t_r8  , 1):ubound(this%a_2d_t_r8  , 1), &
            lbound(this%a_2d_t_r8  , 2):ubound(this%a_2d_t_r8  , 2), &
            1:ie-is+1) => this%a_2d_t_r8  (:,:,is:ie)
      end if
    case default
      nullify(ptr)
      stop 'Unknown location in cubed_sphere_domain_array_get_array_3d_r8_2'
    end select

  end subroutine cubed_sphere_domain_array_get_array_3d_r8_2

  subroutine cubed_sphere_domain_array_get_array_4d_r8_1(this, ptr, var_info)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    real(r8)           , intent(out), pointer                 :: ptr(:,:,:,:)
    type(var_info_type), intent(in )                          :: var_info

    select case (var_info%loc)
    case ('CQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_cq_h_r8, 1):ubound(this%a_3d_cq_h_r8, 1), &
            lbound(this%a_3d_cq_h_r8, 2):ubound(this%a_3d_cq_h_r8, 2), &
            lbound(this%a_3d_cq_h_r8, 3):ubound(this%a_3d_cq_h_r8, 3), &
            lbound(this%a_3d_cq_h_r8, 4):ubound(this%a_3d_cq_h_r8, 4)) => this%a_3d_cq_h_r8(:,:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_cq_r8  , 1):ubound(this%a_3d_cq_r8  , 1), &
            lbound(this%a_3d_cq_r8  , 2):ubound(this%a_3d_cq_r8  , 2), &
            lbound(this%a_3d_cq_r8  , 3):ubound(this%a_3d_cq_r8  , 3), &
            lbound(this%a_3d_cq_r8  , 4):ubound(this%a_3d_cq_r8  , 4)) => this%a_3d_cq_r8  (:,:,:,:,var_info%array_idx)
      end if
    case ('LQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_lq_h_r8, 1):ubound(this%a_3d_lq_h_r8, 1), &
            lbound(this%a_3d_lq_h_r8, 2):ubound(this%a_3d_lq_h_r8, 2), &
            lbound(this%a_3d_lq_h_r8, 3):ubound(this%a_3d_lq_h_r8, 3), &
            lbound(this%a_3d_lq_h_r8, 4):ubound(this%a_3d_lq_h_r8, 4)) => this%a_3d_lq_h_r8(:,:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_lq_r8  , 1):ubound(this%a_3d_lq_r8  , 1), &
            lbound(this%a_3d_lq_r8  , 2):ubound(this%a_3d_lq_r8  , 2), &
            lbound(this%a_3d_lq_r8  , 3):ubound(this%a_3d_lq_r8  , 3), &
            lbound(this%a_3d_lq_r8  , 4):ubound(this%a_3d_lq_r8  , 4)) => this%a_3d_lq_r8  (:,:,:,:,var_info%array_idx)
      end if
    case ('RQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_rq_h_r8, 1):ubound(this%a_3d_rq_h_r8, 1), &
            lbound(this%a_3d_rq_h_r8, 2):ubound(this%a_3d_rq_h_r8, 2), &
            lbound(this%a_3d_rq_h_r8, 3):ubound(this%a_3d_rq_h_r8, 3), &
            lbound(this%a_3d_rq_h_r8, 4):ubound(this%a_3d_rq_h_r8, 4)) => this%a_3d_rq_h_r8(:,:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_rq_r8  , 1):ubound(this%a_3d_rq_r8  , 1), &
            lbound(this%a_3d_rq_r8  , 2):ubound(this%a_3d_rq_r8  , 2), &
            lbound(this%a_3d_rq_r8  , 3):ubound(this%a_3d_rq_r8  , 3), &
            lbound(this%a_3d_rq_r8  , 4):ubound(this%a_3d_rq_r8  , 4)) => this%a_3d_rq_r8  (:,:,:,:,var_info%array_idx)
      end if
    case ('BQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_bq_h_r8, 1):ubound(this%a_3d_bq_h_r8, 1), &
            lbound(this%a_3d_bq_h_r8, 2):ubound(this%a_3d_bq_h_r8, 2), &
            lbound(this%a_3d_bq_h_r8, 3):ubound(this%a_3d_bq_h_r8, 3), &
            lbound(this%a_3d_bq_h_r8, 4):ubound(this%a_3d_bq_h_r8, 4)) => this%a_3d_bq_h_r8(:,:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_bq_r8  , 1):ubound(this%a_3d_bq_r8  , 1), &
            lbound(this%a_3d_bq_r8  , 2):ubound(this%a_3d_bq_r8  , 2), &
            lbound(this%a_3d_bq_r8  , 3):ubound(this%a_3d_bq_r8  , 3), &
            lbound(this%a_3d_bq_r8  , 4):ubound(this%a_3d_bq_r8  , 4)) => this%a_3d_bq_r8  (:,:,:,:,var_info%array_idx)
      end if
    case ('TQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_tq_h_r8, 1):ubound(this%a_3d_tq_h_r8, 1), &
            lbound(this%a_3d_tq_h_r8, 2):ubound(this%a_3d_tq_h_r8, 2), &
            lbound(this%a_3d_tq_h_r8, 3):ubound(this%a_3d_tq_h_r8, 3), &
            lbound(this%a_3d_tq_h_r8, 4):ubound(this%a_3d_tq_h_r8, 4)) => this%a_3d_tq_h_r8(:,:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_tq_r8  , 1):ubound(this%a_3d_tq_r8  , 1), &
            lbound(this%a_3d_tq_r8  , 2):ubound(this%a_3d_tq_r8  , 2), &
            lbound(this%a_3d_tq_r8  , 3):ubound(this%a_3d_tq_r8  , 3), &
            lbound(this%a_3d_tq_r8  , 4):ubound(this%a_3d_tq_r8  , 4)) => this%a_3d_tq_r8  (:,:,:,:,var_info%array_idx)
      end if
    case ('DQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_dq_h_r8, 1):ubound(this%a_3d_dq_h_r8, 1), &
            lbound(this%a_3d_dq_h_r8, 2):ubound(this%a_3d_dq_h_r8, 2), &
            lbound(this%a_3d_dq_h_r8, 3):ubound(this%a_3d_dq_h_r8, 3), &
            lbound(this%a_3d_dq_h_r8, 4):ubound(this%a_3d_dq_h_r8, 4)) => this%a_3d_dq_h_r8(:,:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_dq_r8  , 1):ubound(this%a_3d_dq_r8  , 1), &
            lbound(this%a_3d_dq_r8  , 2):ubound(this%a_3d_dq_r8  , 2), &
            lbound(this%a_3d_dq_r8  , 3):ubound(this%a_3d_dq_r8  , 3), &
            lbound(this%a_3d_dq_r8  , 4):ubound(this%a_3d_dq_r8  , 4)) => this%a_3d_dq_r8  (:,:,:,:,var_info%array_idx)
      end if
    case ('UQ')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_uq_h_r8, 1):ubound(this%a_3d_uq_h_r8, 1), &
            lbound(this%a_3d_uq_h_r8, 2):ubound(this%a_3d_uq_h_r8, 2), &
            lbound(this%a_3d_uq_h_r8, 3):ubound(this%a_3d_uq_h_r8, 3), &
            lbound(this%a_3d_uq_h_r8, 4):ubound(this%a_3d_uq_h_r8, 4)) => this%a_3d_uq_h_r8(:,:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_uq_r8  , 1):ubound(this%a_3d_uq_r8  , 1), &
            lbound(this%a_3d_uq_r8  , 2):ubound(this%a_3d_uq_r8  , 2), &
            lbound(this%a_3d_uq_r8  , 3):ubound(this%a_3d_uq_r8  , 3), &
            lbound(this%a_3d_uq_r8  , 4):ubound(this%a_3d_uq_r8  , 4)) => this%a_3d_uq_r8  (:,:,:,:,var_info%array_idx)
      end if
    case ('G')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_g_h_r8 , 1):ubound(this%a_3d_g_h_r8 , 1), &
            lbound(this%a_3d_g_h_r8 , 2):ubound(this%a_3d_g_h_r8 , 2), &
            lbound(this%a_3d_g_h_r8 , 3):ubound(this%a_3d_g_h_r8 , 3), &
            lbound(this%a_3d_g_h_r8 , 4):ubound(this%a_3d_g_h_r8 , 4)) => this%a_3d_g_h_r8 (:,:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_g_r8   , 1):ubound(this%a_3d_g_r8   , 1), &
            lbound(this%a_3d_g_r8   , 2):ubound(this%a_3d_g_r8   , 2), &
            lbound(this%a_3d_g_r8   , 3):ubound(this%a_3d_g_r8   , 3), &
            lbound(this%a_3d_g_r8   , 4):ubound(this%a_3d_g_r8   , 4)) => this%a_3d_g_r8   (:,:,:,:,var_info%array_idx)
      end if
    case default
      nullify(ptr)
    end select

  end subroutine cubed_sphere_domain_array_get_array_4d_r8_1

  subroutine cubed_sphere_domain_array_get_array_4d_r8_2(this, ptr, loc, with_halo, is, ie)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    real(r8)    , intent(out), pointer                        :: ptr(:,:,:,:)
    character(*), intent(in )                                 :: loc
    logical     , intent(in )                                 :: with_halo
    integer     , intent(in )                                 :: is
    integer     , intent(in )                                 :: ie

    select case (loc)
    case ('C')
      if (with_halo) then
        ptr(lbound(this%a_3d_c_h_r8, 1):ubound(this%a_3d_c_h_r8, 1), &
            lbound(this%a_3d_c_h_r8, 2):ubound(this%a_3d_c_h_r8, 2), &
            lbound(this%a_3d_c_h_r8, 3):ubound(this%a_3d_c_h_r8, 3), &
            1:ie-is+1) => this%a_3d_c_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_c_r8  , 1):ubound(this%a_3d_c_r8  , 1), &
            lbound(this%a_3d_c_r8  , 2):ubound(this%a_3d_c_r8  , 2), &
            lbound(this%a_3d_c_r8  , 3):ubound(this%a_3d_c_r8  , 3), &
            1:ie-is+1) => this%a_3d_c_r8  (:,:,:,is:ie)
      end if
    case ('CA')
      if (with_halo) then
        ptr(lbound(this%a_3d_ca_h_r8, 1):ubound(this%a_3d_ca_h_r8, 1), &
            lbound(this%a_3d_ca_h_r8, 2):ubound(this%a_3d_ca_h_r8, 2), &
            lbound(this%a_3d_ca_h_r8, 3):ubound(this%a_3d_ca_h_r8, 3), &
            1:ie-is+1) => this%a_3d_ca_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_ca_r8  , 1):ubound(this%a_3d_ca_r8  , 1), &
            lbound(this%a_3d_ca_r8  , 2):ubound(this%a_3d_ca_r8  , 2), &
            lbound(this%a_3d_ca_r8  , 3):ubound(this%a_3d_ca_r8  , 3), &
            1:ie-is+1) => this%a_3d_ca_r8  (:,:,:,is:ie)
      end if
    case ('CQ')
      if (with_halo) then
        ptr(lbound(this%a_2d_cq_h_r8, 1):ubound(this%a_2d_cq_h_r8, 1), &
            lbound(this%a_2d_cq_h_r8, 2):ubound(this%a_2d_cq_h_r8, 2), &
            lbound(this%a_2d_cq_h_r8, 3):ubound(this%a_2d_cq_h_r8, 3), &
            1:ie-is+1) => this%a_2d_cq_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_2d_cq_r8  , 1):ubound(this%a_2d_cq_r8  , 1), &
            lbound(this%a_2d_cq_r8  , 2):ubound(this%a_2d_cq_r8  , 2), &
            lbound(this%a_2d_cq_r8  , 3):ubound(this%a_2d_cq_r8  , 3), &
            1:ie-is+1) => this%a_2d_cq_r8  (:,:,:,is:ie)
      end if
    case ('LQ')
      if (with_halo) then
        ptr(lbound(this%a_2d_lq_h_r8, 1):ubound(this%a_2d_lq_h_r8, 1), &
            lbound(this%a_2d_lq_h_r8, 2):ubound(this%a_2d_lq_h_r8, 2), &
            lbound(this%a_2d_lq_h_r8, 3):ubound(this%a_2d_lq_h_r8, 3), &
            1:ie-is+1) => this%a_2d_lq_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_2d_lq_r8  , 1):ubound(this%a_2d_lq_r8  , 1), &
            lbound(this%a_2d_lq_r8  , 2):ubound(this%a_2d_lq_r8  , 2), &
            lbound(this%a_2d_lq_r8  , 3):ubound(this%a_2d_lq_r8  , 3), &
            1:ie-is+1) => this%a_2d_lq_r8  (:,:,:,is:ie)
      end if
    case ('L')
      if (with_halo) then
        ptr(lbound(this%a_3d_l_h_r8, 1):ubound(this%a_3d_l_h_r8, 1), &
            lbound(this%a_3d_l_h_r8, 2):ubound(this%a_3d_l_h_r8, 2), &
            lbound(this%a_3d_l_h_r8, 3):ubound(this%a_3d_l_h_r8, 3), &
            1:ie-is+1) => this%a_3d_l_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_l_r8  , 1):ubound(this%a_3d_l_r8  , 1), &
            lbound(this%a_3d_l_r8  , 2):ubound(this%a_3d_l_r8  , 2), &
            lbound(this%a_3d_l_r8  , 3):ubound(this%a_3d_l_r8  , 3), &
            1:ie-is+1) => this%a_3d_l_r8  (:,:,:,is:ie)
      end if
    case ('RQ')
      if (with_halo) then
        ptr(lbound(this%a_2d_rq_h_r8, 1):ubound(this%a_2d_rq_h_r8, 1), &
            lbound(this%a_2d_rq_h_r8, 2):ubound(this%a_2d_rq_h_r8, 2), &
            lbound(this%a_2d_rq_h_r8, 3):ubound(this%a_2d_rq_h_r8, 3), &
            1:ie-is+1) => this%a_2d_rq_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_2d_rq_r8  , 1):ubound(this%a_2d_rq_r8  , 1), &
            lbound(this%a_2d_rq_r8  , 2):ubound(this%a_2d_rq_r8  , 2), &
            lbound(this%a_2d_rq_r8  , 3):ubound(this%a_2d_rq_r8  , 3), &
            1:ie-is+1) => this%a_2d_rq_r8  (:,:,:,is:ie)
      end if
    case ('R')
      if (with_halo) then
        ptr(lbound(this%a_3d_r_h_r8, 1):ubound(this%a_3d_r_h_r8, 1), &
            lbound(this%a_3d_r_h_r8, 2):ubound(this%a_3d_r_h_r8, 2), &
            lbound(this%a_3d_r_h_r8, 3):ubound(this%a_3d_r_h_r8, 3), &
            1:ie-is+1) => this%a_3d_r_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_r_r8  , 1):ubound(this%a_3d_r_r8  , 1), &
            lbound(this%a_3d_r_r8  , 2):ubound(this%a_3d_r_r8  , 2), &
            lbound(this%a_3d_r_r8  , 3):ubound(this%a_3d_r_r8  , 3), &
            1:ie-is+1) => this%a_3d_r_r8  (:,:,:,is:ie)
      end if
    case ('BQ')
      if (with_halo) then
        ptr(lbound(this%a_2d_bq_h_r8, 1):ubound(this%a_2d_bq_h_r8, 1), &
            lbound(this%a_2d_bq_h_r8, 2):ubound(this%a_2d_bq_h_r8, 2), &
            lbound(this%a_2d_bq_h_r8, 3):ubound(this%a_2d_bq_h_r8, 3), &
            1:ie-is+1) => this%a_2d_bq_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_2d_bq_r8  , 1):ubound(this%a_2d_bq_r8  , 1), &
            lbound(this%a_2d_bq_r8  , 2):ubound(this%a_2d_bq_r8  , 2), &
            lbound(this%a_2d_bq_r8  , 3):ubound(this%a_2d_bq_r8  , 3), &
            1:ie-is+1) => this%a_2d_bq_r8  (:,:,:,is:ie)
      end if
    case ('B')
      if (with_halo) then
        ptr(lbound(this%a_3d_b_h_r8, 1):ubound(this%a_3d_b_h_r8, 1), &
            lbound(this%a_3d_b_h_r8, 2):ubound(this%a_3d_b_h_r8, 2), &
            lbound(this%a_3d_b_h_r8, 3):ubound(this%a_3d_b_h_r8, 3), &
            1:ie-is+1) => this%a_3d_b_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_b_r8  , 1):ubound(this%a_3d_b_r8  , 1), &
            lbound(this%a_3d_b_r8  , 2):ubound(this%a_3d_b_r8  , 2), &
            lbound(this%a_3d_b_r8  , 3):ubound(this%a_3d_b_r8  , 3), &
            1:ie-is+1) => this%a_3d_b_r8  (:,:,:,is:ie)
      end if
    case ('TQ')
      if (with_halo) then
        ptr(lbound(this%a_2d_tq_h_r8, 1):ubound(this%a_2d_tq_h_r8, 1), &
            lbound(this%a_2d_tq_h_r8, 2):ubound(this%a_2d_tq_h_r8, 2), &
            lbound(this%a_2d_tq_h_r8, 3):ubound(this%a_2d_tq_h_r8, 3), &
            1:ie-is+1) => this%a_2d_tq_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_2d_tq_r8  , 1):ubound(this%a_2d_tq_r8  , 1), &
            lbound(this%a_2d_tq_r8  , 2):ubound(this%a_2d_tq_r8  , 2), &
            lbound(this%a_2d_tq_r8  , 3):ubound(this%a_2d_tq_r8  , 3), &
            1:ie-is+1) => this%a_2d_tq_r8  (:,:,:,is:ie)
      end if
    case ('T')
      if (with_halo) then
        ptr(lbound(this%a_3d_t_h_r8, 1):ubound(this%a_3d_t_h_r8, 1), &
            lbound(this%a_3d_t_h_r8, 2):ubound(this%a_3d_t_h_r8, 2), &
            lbound(this%a_3d_t_h_r8, 3):ubound(this%a_3d_t_h_r8, 3), &
            1:ie-is+1) => this%a_3d_t_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_t_r8  , 1):ubound(this%a_3d_t_r8  , 1), &
            lbound(this%a_3d_t_r8  , 2):ubound(this%a_3d_t_r8  , 2), &
            lbound(this%a_3d_t_r8  , 3):ubound(this%a_3d_t_r8  , 3), &
            1:ie-is+1) => this%a_3d_t_r8  (:,:,:,is:ie)
      end if
    case ('DQ')
      if (with_halo) then
        ptr(lbound(this%a_2d_dq_h_r8, 1):ubound(this%a_2d_dq_h_r8, 1), &
            lbound(this%a_2d_dq_h_r8, 2):ubound(this%a_2d_dq_h_r8, 2), &
            lbound(this%a_2d_dq_h_r8, 3):ubound(this%a_2d_dq_h_r8, 3), &
            1:ie-is+1) => this%a_2d_dq_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_2d_dq_r8  , 1):ubound(this%a_2d_dq_r8  , 1), &
            lbound(this%a_2d_dq_r8  , 2):ubound(this%a_2d_dq_r8  , 2), &
            lbound(this%a_2d_dq_r8  , 3):ubound(this%a_2d_dq_r8  , 3), &
            1:ie-is+1) => this%a_2d_dq_r8  (:,:,:,is:ie)
      end if
    case ('D')
      if (with_halo) then
        ptr(lbound(this%a_3d_d_h_r8, 1):ubound(this%a_3d_d_h_r8, 1), &
            lbound(this%a_3d_d_h_r8, 2):ubound(this%a_3d_d_h_r8, 2), &
            lbound(this%a_3d_d_h_r8, 3):ubound(this%a_3d_d_h_r8, 3), &
            1:ie-is+1) => this%a_3d_d_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_d_r8  , 1):ubound(this%a_3d_d_r8  , 1), &
            lbound(this%a_3d_d_r8  , 2):ubound(this%a_3d_d_r8  , 2), &
            lbound(this%a_3d_d_r8  , 3):ubound(this%a_3d_d_r8  , 3), &
            1:ie-is+1) => this%a_3d_d_r8  (:,:,:,is:ie)
      end if
    case ('UQ')
      if (with_halo) then
        ptr(lbound(this%a_2d_uq_h_r8, 1):ubound(this%a_2d_uq_h_r8, 1), &
            lbound(this%a_2d_uq_h_r8, 2):ubound(this%a_2d_uq_h_r8, 2), &
            lbound(this%a_2d_uq_h_r8, 3):ubound(this%a_2d_uq_h_r8, 3), &
            1:ie-is+1) => this%a_2d_uq_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_2d_uq_r8  , 1):ubound(this%a_2d_uq_r8  , 1), &
            lbound(this%a_2d_uq_r8  , 2):ubound(this%a_2d_uq_r8  , 2), &
            lbound(this%a_2d_uq_r8  , 3):ubound(this%a_2d_uq_r8  , 3), &
            1:ie-is+1) => this%a_2d_uq_r8  (:,:,:,is:ie)
      end if
    case ('U')
      if (with_halo) then
        ptr(lbound(this%a_3d_u_h_r8, 1):ubound(this%a_3d_u_h_r8, 1), &
            lbound(this%a_3d_u_h_r8, 2):ubound(this%a_3d_u_h_r8, 2), &
            lbound(this%a_3d_u_h_r8, 3):ubound(this%a_3d_u_h_r8, 3), &
            1:ie-is+1) => this%a_3d_u_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_u_r8  , 1):ubound(this%a_3d_u_r8  , 1), &
            lbound(this%a_3d_u_r8  , 2):ubound(this%a_3d_u_r8  , 2), &
            lbound(this%a_3d_u_r8  , 3):ubound(this%a_3d_u_r8  , 3), &
            1:ie-is+1) => this%a_3d_u_r8  (:,:,:,is:ie)
      end if
    case ('G')
      if (with_halo) then
        ptr(lbound(this%a_2d_g_h_r8, 1):ubound(this%a_2d_g_h_r8, 1), &
            lbound(this%a_2d_g_h_r8, 2):ubound(this%a_2d_g_h_r8, 2), &
            lbound(this%a_2d_g_h_r8, 3):ubound(this%a_2d_g_h_r8, 3), &
            1:ie-is+1) => this%a_2d_g_h_r8(:,:,:,is:ie)
      else
        ptr(lbound(this%a_2d_g_r8  , 1):ubound(this%a_2d_g_r8  , 1), &
            lbound(this%a_2d_g_r8  , 2):ubound(this%a_2d_g_r8  , 2), &
            lbound(this%a_2d_g_r8  , 3):ubound(this%a_2d_g_r8  , 3), &
            1:ie-is+1) => this%a_2d_g_r8  (:,:,:,is:ie)
      end if
    case default
      nullify(ptr)
    end select

  end subroutine cubed_sphere_domain_array_get_array_4d_r8_2

  subroutine cubed_sphere_domain_array_get_array_5d_r8(this, ptr, loc, with_halo, is, ie)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    real(r8)    , intent(out), pointer                        :: ptr(:,:,:,:,:)
    character(*), intent(in )                                 :: loc
    logical     , intent(in )                                 :: with_halo
    integer     , intent(in )                                 :: is
    integer     , intent(in )                                 :: ie

    select case (loc)
    case ('CQ')
      if (with_halo) then
        ptr(lbound(this%a_3d_cq_h_r8, 1):ubound(this%a_3d_cq_h_r8, 1), &
            lbound(this%a_3d_cq_h_r8, 2):ubound(this%a_3d_cq_h_r8, 2), &
            lbound(this%a_3d_cq_h_r8, 3):ubound(this%a_3d_cq_h_r8, 3), &
            lbound(this%a_3d_cq_h_r8, 4):ubound(this%a_3d_cq_h_r8, 4), &
            1:ie-is+1) => this%a_3d_cq_h_r8(:,:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_cq_r8  , 1):ubound(this%a_3d_cq_r8  , 1), &
            lbound(this%a_3d_cq_r8  , 2):ubound(this%a_3d_cq_r8  , 2), &
            lbound(this%a_3d_cq_r8  , 3):ubound(this%a_3d_cq_r8  , 3), &
            lbound(this%a_3d_cq_r8  , 4):ubound(this%a_3d_cq_r8  , 4), &
            1:ie-is+1) => this%a_3d_cq_r8  (:,:,:,:,is:ie)
      end if
    case ('LQ')
      if (with_halo) then
        ptr(lbound(this%a_3d_lq_h_r8, 1):ubound(this%a_3d_lq_h_r8, 1), &
            lbound(this%a_3d_lq_h_r8, 2):ubound(this%a_3d_lq_h_r8, 2), &
            lbound(this%a_3d_lq_h_r8, 3):ubound(this%a_3d_lq_h_r8, 3), &
            lbound(this%a_3d_lq_h_r8, 4):ubound(this%a_3d_lq_h_r8, 4), &
            1:ie-is+1) => this%a_3d_lq_h_r8(:,:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_lq_r8  , 1):ubound(this%a_3d_lq_r8  , 1), &
            lbound(this%a_3d_lq_r8  , 2):ubound(this%a_3d_lq_r8  , 2), &
            lbound(this%a_3d_lq_r8  , 3):ubound(this%a_3d_lq_r8  , 3), &
            lbound(this%a_3d_lq_r8  , 4):ubound(this%a_3d_lq_r8  , 4), &
            1:ie-is+1) => this%a_3d_lq_r8  (:,:,:,:,is:ie)
      end if
    case ('RQ')
      if (with_halo) then
        ptr(lbound(this%a_3d_rq_h_r8, 1):ubound(this%a_3d_rq_h_r8, 1), &
            lbound(this%a_3d_rq_h_r8, 2):ubound(this%a_3d_rq_h_r8, 2), &
            lbound(this%a_3d_rq_h_r8, 3):ubound(this%a_3d_rq_h_r8, 3), &
            lbound(this%a_3d_rq_h_r8, 4):ubound(this%a_3d_rq_h_r8, 4), &
            1:ie-is+1) => this%a_3d_rq_h_r8(:,:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_rq_r8  , 1):ubound(this%a_3d_rq_r8  , 1), &
            lbound(this%a_3d_rq_r8  , 2):ubound(this%a_3d_rq_r8  , 2), &
            lbound(this%a_3d_rq_r8  , 3):ubound(this%a_3d_rq_r8  , 3), &
            lbound(this%a_3d_rq_r8  , 4):ubound(this%a_3d_rq_r8  , 4), &
            1:ie-is+1) => this%a_3d_rq_r8  (:,:,:,:,is:ie)
      end if
    case ('BQ')
      if (with_halo) then
        ptr(lbound(this%a_3d_bq_h_r8, 1):ubound(this%a_3d_bq_h_r8, 1), &
            lbound(this%a_3d_bq_h_r8, 2):ubound(this%a_3d_bq_h_r8, 2), &
            lbound(this%a_3d_bq_h_r8, 3):ubound(this%a_3d_bq_h_r8, 3), &
            lbound(this%a_3d_bq_h_r8, 4):ubound(this%a_3d_bq_h_r8, 4), &
            1:ie-is+1) => this%a_3d_bq_h_r8(:,:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_bq_r8  , 1):ubound(this%a_3d_bq_r8  , 1), &
            lbound(this%a_3d_bq_r8  , 2):ubound(this%a_3d_bq_r8  , 2), &
            lbound(this%a_3d_bq_r8  , 3):ubound(this%a_3d_bq_r8  , 3), &
            lbound(this%a_3d_bq_r8  , 4):ubound(this%a_3d_bq_r8  , 4), &
            1:ie-is+1) => this%a_3d_bq_r8  (:,:,:,:,is:ie)
      end if
    case ('TQ')
      if (with_halo) then
        ptr(lbound(this%a_3d_tq_h_r8, 1):ubound(this%a_3d_tq_h_r8, 1), &
            lbound(this%a_3d_tq_h_r8, 2):ubound(this%a_3d_tq_h_r8, 2), &
            lbound(this%a_3d_tq_h_r8, 3):ubound(this%a_3d_tq_h_r8, 3), &
            lbound(this%a_3d_tq_h_r8, 4):ubound(this%a_3d_tq_h_r8, 4), &
            1:ie-is+1) => this%a_3d_tq_h_r8(:,:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_tq_r8  , 1):ubound(this%a_3d_tq_r8  , 1), &
            lbound(this%a_3d_tq_r8  , 2):ubound(this%a_3d_tq_r8  , 2), &
            lbound(this%a_3d_tq_r8  , 3):ubound(this%a_3d_tq_r8  , 3), &
            lbound(this%a_3d_tq_r8  , 4):ubound(this%a_3d_tq_r8  , 4), &
            1:ie-is+1) => this%a_3d_tq_r8  (:,:,:,:,is:ie)
      end if
    case ('DQ')
      if (with_halo) then
        ptr(lbound(this%a_3d_dq_h_r8, 1):ubound(this%a_3d_dq_h_r8, 1), &
            lbound(this%a_3d_dq_h_r8, 2):ubound(this%a_3d_dq_h_r8, 2), &
            lbound(this%a_3d_dq_h_r8, 3):ubound(this%a_3d_dq_h_r8, 3), &
            lbound(this%a_3d_dq_h_r8, 4):ubound(this%a_3d_dq_h_r8, 4), &
            1:ie-is+1) => this%a_3d_dq_h_r8(:,:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_dq_r8  , 1):ubound(this%a_3d_dq_r8  , 1), &
            lbound(this%a_3d_dq_r8  , 2):ubound(this%a_3d_dq_r8  , 2), &
            lbound(this%a_3d_dq_r8  , 3):ubound(this%a_3d_dq_r8  , 3), &
            lbound(this%a_3d_dq_r8  , 4):ubound(this%a_3d_dq_r8  , 4), &
            1:ie-is+1) => this%a_3d_dq_r8  (:,:,:,:,is:ie)
      end if
    case ('UQ')
      if (with_halo) then
        ptr(lbound(this%a_3d_uq_h_r8, 1):ubound(this%a_3d_uq_h_r8, 1), &
            lbound(this%a_3d_uq_h_r8, 2):ubound(this%a_3d_uq_h_r8, 2), &
            lbound(this%a_3d_uq_h_r8, 3):ubound(this%a_3d_uq_h_r8, 3), &
            lbound(this%a_3d_uq_h_r8, 4):ubound(this%a_3d_uq_h_r8, 4), &
            1:ie-is+1) => this%a_3d_uq_h_r8(:,:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_uq_r8  , 1):ubound(this%a_3d_uq_r8  , 1), &
            lbound(this%a_3d_uq_r8  , 2):ubound(this%a_3d_uq_r8  , 2), &
            lbound(this%a_3d_uq_r8  , 3):ubound(this%a_3d_uq_r8  , 3), &
            lbound(this%a_3d_uq_r8  , 4):ubound(this%a_3d_uq_r8  , 4), &
            1:ie-is+1) => this%a_3d_uq_r8  (:,:,:,:,is:ie)
      end if
    case ('G')
      if (with_halo) then
        ptr(lbound(this%a_3d_g_h_r8 , 1):ubound(this%a_3d_g_h_r8 , 1), &
            lbound(this%a_3d_g_h_r8 , 2):ubound(this%a_3d_g_h_r8 , 2), &
            lbound(this%a_3d_g_h_r8 , 3):ubound(this%a_3d_g_h_r8 , 3), &
            lbound(this%a_3d_g_h_r8 , 4):ubound(this%a_3d_g_h_r8 , 4), &
            1:ie-is+1) => this%a_3d_g_h_r8 (:,:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_g_r8   , 1):ubound(this%a_3d_g_r8   , 1), &
            lbound(this%a_3d_g_r8   , 2):ubound(this%a_3d_g_r8   , 2), &
            lbound(this%a_3d_g_r8   , 3):ubound(this%a_3d_g_r8   , 3), &
            lbound(this%a_3d_g_r8   , 4):ubound(this%a_3d_g_r8   , 4), &
            1:ie-is+1) => this%a_3d_g_h_r8 (:,:,:,:,is:ie)
      end if
    case default
      nullify(ptr)
    end select

  end subroutine cubed_sphere_domain_array_get_array_5d_r8

  subroutine cubed_sphere_domain_array_get_array_2d_l_1(this, ptr, loc, with_halo, is, ie)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    logical     , intent(out), pointer                        :: ptr(:,:,:)
    character(*), intent(in )                                 :: loc
    logical     , intent(in )                                 :: with_halo
    integer     , intent(in )                                 :: is
    integer     , intent(in )                                 :: ie

    nullify(ptr)
    select case (loc)
    case ('C')
      if (with_halo) then
        ptr(lbound(this%a_2d_c_h_l, 1):ubound(this%a_2d_c_h_l, 1), &
            lbound(this%a_2d_c_h_l, 2):ubound(this%a_2d_c_h_l, 2), &
            1:ie-is+1) => this%a_2d_c_h_l(:,:,is:ie)
      else
        ptr(lbound(this%a_2d_c_l, 1):ubound(this%a_2d_c_l, 1), &
            lbound(this%a_2d_c_l, 2):ubound(this%a_2d_c_l, 2), &
            1:ie-is+1) => this%a_2d_c_l(:,:,is:ie)
      end if
    end select

  end subroutine cubed_sphere_domain_array_get_array_2d_l_1

  subroutine cubed_sphere_domain_array_get_array_2d_i4_1(this, ptr, loc, with_halo, var_info)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    integer     , intent(out), pointer                        :: ptr(:,:)
    character(*), intent(in )                                 :: loc
    logical     , intent(in )                                 :: with_halo
    type(var_info_type), intent(in )                          :: var_info

    nullify(ptr)
    select case (loc)
    case ('C')
      if (with_halo) then
        ptr(lbound(this%a_2d_c_h_i4, 1):ubound(this%a_2d_c_h_i4, 1), &
            lbound(this%a_2d_c_h_i4, 2):ubound(this%a_2d_c_h_i4, 2)) => this%a_2d_c_h_i4(:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_c_i4, 1):ubound(this%a_2d_c_i4, 1), &
            lbound(this%a_2d_c_i4, 2):ubound(this%a_2d_c_i4, 2)) => this%a_2d_c_i4(:,:,var_info%array_idx)
      end if
    case ('CA')
      if (with_halo) then
        ptr(lbound(this%a_2d_ca_h_i4, 1):ubound(this%a_2d_ca_h_i4, 1), &
            lbound(this%a_2d_ca_h_i4, 2):ubound(this%a_2d_ca_h_i4, 2)) => this%a_2d_ca_h_i4(:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_2d_ca_i4, 1):ubound(this%a_2d_ca_i4, 1), &
            lbound(this%a_2d_ca_i4, 2):ubound(this%a_2d_ca_i4, 2)) => this%a_2d_ca_i4(:,:,var_info%array_idx)
      end if
    end select

  end subroutine cubed_sphere_domain_array_get_array_2d_i4_1

  subroutine cubed_sphere_domain_array_get_array_2d_i4_2(this, ptr, loc, with_halo, is, ie)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    integer     , intent(out), pointer                        :: ptr(:,:,:)
    character(*), intent(in )                                 :: loc
    logical     , intent(in )                                 :: with_halo
    integer     , intent(in )                                 :: is
    integer     , intent(in )                                 :: ie

    nullify(ptr)
    select case (loc)
    case ('C')
      if (with_halo) then
        ptr(lbound(this%a_2d_c_h_i4, 1):ubound(this%a_2d_c_h_i4, 1), &
            lbound(this%a_2d_c_h_i4, 2):ubound(this%a_2d_c_h_i4, 2), &
            1:ie-is+1) => this%a_2d_c_h_i4(:,:,is:ie)
      else
        ptr(lbound(this%a_2d_c_i4, 1):ubound(this%a_2d_c_i4, 1), &
            lbound(this%a_2d_c_i4, 2):ubound(this%a_2d_c_i4, 2), &
            1:ie-is+1) => this%a_2d_c_i4(:,:,is:ie)
      end if
    case ('CA')
      if (with_halo) then
        ptr(lbound(this%a_2d_ca_h_i4, 1):ubound(this%a_2d_ca_h_i4, 1), &
            lbound(this%a_2d_ca_h_i4, 2):ubound(this%a_2d_ca_h_i4, 2), &
            1:ie-is+1) => this%a_2d_ca_h_i4(:,:,is:ie)
      else
        ptr(lbound(this%a_2d_ca_i4, 1):ubound(this%a_2d_ca_i4, 1), &
            lbound(this%a_2d_ca_i4, 2):ubound(this%a_2d_ca_i4, 2), &
            1:ie-is+1) => this%a_2d_ca_i4(:,:,is:ie)
      end if
    end select

  end subroutine cubed_sphere_domain_array_get_array_2d_i4_2

  subroutine cubed_sphere_domain_array_get_array_3d_l_1(this, ptr, loc, with_halo, is, ie)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    logical     , intent(out), pointer                        :: ptr(:,:,:,:)
    character(*), intent(in )                                 :: loc
    logical     , intent(in )                                 :: with_halo
    integer     , intent(in )                                 :: is
    integer     , intent(in )                                 :: ie

    nullify(ptr)
    select case (loc)
    case ('C')
      if (with_halo) then
        ptr(lbound(this%a_3d_c_h_l, 1):ubound(this%a_3d_c_h_l, 1), &
            lbound(this%a_3d_c_h_l, 2):ubound(this%a_3d_c_h_l, 2), &
            lbound(this%a_3d_c_h_l, 3):ubound(this%a_3d_c_h_l, 3), &
            1:ie-is+1) => this%a_3d_c_h_l(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_c_l, 1):ubound(this%a_3d_c_l, 1), &
            lbound(this%a_3d_c_l, 2):ubound(this%a_3d_c_l, 2), &
            lbound(this%a_3d_c_l, 3):ubound(this%a_3d_c_l, 3), &
            1:ie-is+1) => this%a_3d_c_l(:,:,:,is:ie)
      end if
    end select

  end subroutine cubed_sphere_domain_array_get_array_3d_l_1

  subroutine cubed_sphere_domain_array_get_array_3d_i4_1(this, ptr, var_info)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    integer            , intent(out), pointer                 :: ptr(:,:,:)
    type(var_info_type), intent(in )                          :: var_info

    select case (var_info%loc)
    case ('C')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_c_h_i4, 1):ubound(this%a_3d_c_h_i4, 1), &
            lbound(this%a_3d_c_h_i4, 2):ubound(this%a_3d_c_h_i4, 2), &
            lbound(this%a_3d_c_h_i4, 3):ubound(this%a_3d_c_h_i4, 3)) => this%a_3d_c_h_i4(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_c_i4  , 1):ubound(this%a_3d_c_i4  , 1), &
            lbound(this%a_3d_c_i4  , 2):ubound(this%a_3d_c_i4  , 2), &
            lbound(this%a_3d_c_i4  , 3):ubound(this%a_3d_c_i4  , 3)) => this%a_3d_c_i4  (:,:,:,var_info%array_idx)
      end if
    case ('CA')
      if (var_info%with_halo) then
        ptr(lbound(this%a_3d_ca_h_i4, 1):ubound(this%a_3d_ca_h_i4, 1), &
            lbound(this%a_3d_ca_h_i4, 2):ubound(this%a_3d_ca_h_i4, 2), &
            lbound(this%a_3d_ca_h_i4, 3):ubound(this%a_3d_ca_h_i4, 3)) => this%a_3d_ca_h_i4(:,:,:,var_info%array_idx)
      else
        ptr(lbound(this%a_3d_ca_i4  , 1):ubound(this%a_3d_ca_i4  , 1), &
            lbound(this%a_3d_ca_i4  , 2):ubound(this%a_3d_ca_i4  , 2), &
            lbound(this%a_3d_ca_i4  , 3):ubound(this%a_3d_ca_i4  , 3)) => this%a_3d_ca_i4  (:,:,:,var_info%array_idx)
      end if
    case default
      nullify(ptr)
    end select

  end subroutine cubed_sphere_domain_array_get_array_3d_i4_1

  subroutine cubed_sphere_domain_array_get_array_3d_i4_2(this, ptr, loc, with_halo, is, ie)

    class(cubed_sphere_domain_array_type), intent(in), target :: this
    integer     , intent(out), pointer                        :: ptr(:,:,:,:)
    character(*), intent(in )                                 :: loc
    logical     , intent(in )                                 :: with_halo
    integer     , intent(in )                                 :: is
    integer     , intent(in )                                 :: ie

    nullify(ptr)
    select case (loc)
    case ('C')
      if (with_halo) then
        ptr(lbound(this%a_3d_c_h_i4, 1):ubound(this%a_3d_c_h_i4, 1), &
            lbound(this%a_3d_c_h_i4, 2):ubound(this%a_3d_c_h_i4, 2), &
            lbound(this%a_3d_c_h_i4, 3):ubound(this%a_3d_c_h_i4, 3), &
            1:ie-is+1) => this%a_3d_c_h_i4(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_c_i4, 1):ubound(this%a_3d_c_i4, 1), &
            lbound(this%a_3d_c_i4, 2):ubound(this%a_3d_c_i4, 2), &
            lbound(this%a_3d_c_i4, 3):ubound(this%a_3d_c_i4, 3), &
            1:ie-is+1) => this%a_3d_c_i4(:,:,:,is:ie)
      end if
    case ('CA')
      if (with_halo) then
        ptr(lbound(this%a_3d_ca_h_i4, 1):ubound(this%a_3d_ca_h_i4, 1), &
            lbound(this%a_3d_ca_h_i4, 2):ubound(this%a_3d_ca_h_i4, 2), &
            lbound(this%a_3d_ca_h_i4, 3):ubound(this%a_3d_ca_h_i4, 3), &
            1:ie-is+1) => this%a_3d_ca_h_i4(:,:,:,is:ie)
      else
        ptr(lbound(this%a_3d_ca_i4, 1):ubound(this%a_3d_ca_i4, 1), &
            lbound(this%a_3d_ca_i4, 2):ubound(this%a_3d_ca_i4, 2), &
            lbound(this%a_3d_ca_i4, 3):ubound(this%a_3d_ca_i4, 3), &
            1:ie-is+1) => this%a_3d_ca_i4(:,:,:,is:ie)
      end if
    end select

  end subroutine cubed_sphere_domain_array_get_array_3d_i4_2

  subroutine cubed_sphere_domain_array_final(this)

    type(cubed_sphere_domain_array_type), intent(inout) :: this

    call this%clear()

  end subroutine cubed_sphere_domain_array_final

end module cubed_sphere_domain_array_mod
